From 0590e099a8e0ef09cf88156e990fcb9a85d802c7 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Tue, 4 Jan 2022 11:22:13 +0000 Subject: [PATCH 01/11] fix markdown fail in fly.md #72 --- fly-phoenix-setup.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fly-phoenix-setup.md b/fly-phoenix-setup.md index 569c1da..7b8856e 100644 --- a/fly-phoenix-setup.md +++ b/fly-phoenix-setup.md @@ -4,10 +4,10 @@ is a new type of Platform-as-a-Service (PaaS) for deploying web Apps/APIs closer to the people _using_ them. -Much like a +Much like a [Content Delivery Network](https://en.wikipedia.org/wiki/Content_delivery_network) (CDN) -where there are copies of your `static` content +where there are copies of your `static` content stored on "edge" nodes close to the people (devices) _consuming_ the content, Fly.io replicates your Application @@ -20,11 +20,11 @@ and they are committed to making the experience great. -##Β What? +## What? -A new way of deploying Elixir/Phoenix apps that will continue to get better because they -[_hired_ Chris McCord](https://github.com/dwyl/learn-devops/issues/72#issuecomment-917442712) -(creator of Phoenix!!) +A new way of deploying Elixir/Phoenix apps that will continue to get better because they +[_hired_ Chris McCord](https://github.com/dwyl/learn-devops/issues/72#issuecomment-917442712) +(creator of Phoenix!!) ## Pricing? @@ -34,14 +34,15 @@ See: [learn-devops/issues/72][https://github.com/dwyl/learn-devops/issues/72#iss ### Venture Capital (VC) Funding? -Fly.io are funded by +Fly.io are funded by [YCombinator and a few others](https://www.crunchbase.com/organization/fly-io/company_financials) -Obviously we would _prefer_ if they were independent, -but we totally understand that +... +Obviously, we would _prefer_ if they were independent, +but we totally understand that building this kind of service requires considerable capital investment in the form of both infrastructure and engineers. -I suspect they are piggy-backing on AWS/GCP/etc +I suspect they are piggy-backing on AWS/GCP/etc rather than running their own servers. But they still have the job of making it all seamless. From 4b5ef53b92edf92733cec2090eb5e5ed365599ad Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sat, 9 Apr 2022 02:39:51 +0100 Subject: [PATCH 02/11] start documenting setup of Gogs for #79 --- gogs/README.md | 57 +++++++++++++++++++ linode-setup.md => linode/README.md | 0 {vagrant-linode => linode}/Vagrantfile | 0 {vagrant-linode => linode}/apache.sh | 0 .../apache2/ports1.conf | 0 .../apache2/sites-available/vhost.conf | 0 {vagrant-linode => linode}/setup.sh | 0 7 files changed, 57 insertions(+) create mode 100644 gogs/README.md rename linode-setup.md => linode/README.md (100%) rename {vagrant-linode => linode}/Vagrantfile (100%) rename {vagrant-linode => linode}/apache.sh (100%) rename {vagrant-linode => linode}/apache2/ports1.conf (100%) rename {vagrant-linode => linode}/apache2/sites-available/vhost.conf (100%) rename {vagrant-linode => linode}/setup.sh (100%) diff --git a/gogs/README.md b/gogs/README.md new file mode 100644 index 0000000..acfa932 --- /dev/null +++ b/gogs/README.md @@ -0,0 +1,57 @@ +
+

Learn, Deploy and Maintain a Gogs Server

+ + + +

+ A quick guide to + Gogs (Git Server) + for complete beginners. +

+ +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/learn-travis/issues) +[![HitCount](http://hits.dwyl.com/dwyl/learn-devops-gogs.svg)](http://hits.dwyl.com/dwyl/learn-devops-gogs) + +
+ +# _Why_? πŸ€·β€β™‚οΈ + +You need a simple **Git server** +without the steep learning curve of +[Git SCM](https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server) +or _overhead_ of running a **GitLab** instance. + +**`Gogs`** is a performance-friendly +Git web interface written in the **`Go`** programming language. +It claims to make setting up and managing GIT painless; +let's test that! + + +# _What_? πŸ“¦ + +In our case **`@dwyl`**, +we are _mostly_ happy with the GitHub service. πŸ‘Œ
+Except for a few annoying aspects of the interface +and the occasional outage, GitHub is good. +We are exploring having a **`Gogs`** server running as a +[**_hot_ backup**](https://en.wikipedia.org/wiki/Backup_site#Hot_site). + +# _Who_? πŸ€“ + +The audience for this guide is "_us_".
+If anyone `else` finds it helpful that's a bonus.
+Please ⭐ the repo if you find it useful. + +# _How_? πŸ‘©β€πŸ’» + + + + + +## Reading πŸ“š + + +Pages we read on the journey: + ++ https://pimylifeup.com/raspberry-pi-gogs/ + diff --git a/linode-setup.md b/linode/README.md similarity index 100% rename from linode-setup.md rename to linode/README.md diff --git a/vagrant-linode/Vagrantfile b/linode/Vagrantfile similarity index 100% rename from vagrant-linode/Vagrantfile rename to linode/Vagrantfile diff --git a/vagrant-linode/apache.sh b/linode/apache.sh similarity index 100% rename from vagrant-linode/apache.sh rename to linode/apache.sh diff --git a/vagrant-linode/apache2/ports1.conf b/linode/apache2/ports1.conf similarity index 100% rename from vagrant-linode/apache2/ports1.conf rename to linode/apache2/ports1.conf diff --git a/vagrant-linode/apache2/sites-available/vhost.conf b/linode/apache2/sites-available/vhost.conf similarity index 100% rename from vagrant-linode/apache2/sites-available/vhost.conf rename to linode/apache2/sites-available/vhost.conf diff --git a/vagrant-linode/setup.sh b/linode/setup.sh similarity index 100% rename from vagrant-linode/setup.sh rename to linode/setup.sh From 07a74cac36b1ccbde1fb8490a7345fa14b59b4b0 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 10 Apr 2022 09:07:54 +0100 Subject: [PATCH 03/11] create gogs/install-gogs-raspberrypi.md #79 --- gogs/README.md | 11 +- gogs/install-gogs-raspberrypi.md | 205 +++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+), 4 deletions(-) create mode 100644 gogs/install-gogs-raspberrypi.md diff --git a/gogs/README.md b/gogs/README.md index acfa932..c9d4a99 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -1,5 +1,5 @@
-

Learn, Deploy and Maintain a Gogs Server

+

Learn to Deploy & Maintain a Gogs Server

@@ -9,7 +9,7 @@ for complete beginners.

-[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/learn-travis/issues) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/learn-travis/issues) [![HitCount](http://hits.dwyl.com/dwyl/learn-devops-gogs.svg)](http://hits.dwyl.com/dwyl/learn-devops-gogs)
@@ -38,12 +38,15 @@ We are exploring having a **`Gogs`** server running as a # _Who_? πŸ€“ -The audience for this guide is "_us_".
+The audience for this guide is "_us_" +[**`@dwyl`**](https://github.com/dwyl).
If anyone `else` finds it helpful that's a bonus.
-Please ⭐ the repo if you find it useful. +Please ⭐ the repo if you find it useful. Thanks! # _How_? πŸ‘©β€πŸ’» +Continue: + diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md new file mode 100644 index 0000000..39edb29 --- /dev/null +++ b/gogs/install-gogs-raspberrypi.md @@ -0,0 +1,205 @@ +# Install Gogs on Raspberry Pi + +This guide follows and expands +on the official **`Gogs`** +installation guide: +https://gogs.io/docs/installation ... + +Our objective is to capture _all_ the steps +required so that _anyone_ can follow along +and replicate our _exact_ result. + + +## Prerequisites + +Ensure you have a working Raspberry Pi running +Ubuntu: +https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview + + +> We are using Ubuntu because it's _ubiquitous_ +> and will help with deployment to Cloud/VPS later +> so getting it working on the Pi is a good first step. βœ… + + +### **`Postgres`** + +The default DB for **`Gogs`** +is be **`MySQL`**, +but we prefer **`Postgres`**. + +Install Postgres on Ubuntu: +[learn-postgresql#ubuntu](https://github.com/dwyl/learn-postgresql#ubuntu) + +```sh +sudo apt-get install -y postgresql postgresql-contrib postgresql-client libpq-dev +``` +
+ +### `git` + +Install `git` if not already installed in your Ubuntu instance: + +```sh +sudo apt update && sudo apt upgrade +sudo apt-get install -y git +``` + +If you see something similar to the following: + +```sh +git is already the newest version (1:2.25.1-1ubuntu3.2). +``` + +You already have `git` and can proceed. + +Create a new user called `git` to run `gogs`: + +```sh +sudo adduser --disabled-login --gecos 'Gogs' git +``` + +
+ +### `Go`s + +We are going to compile `gogs` from source +so we need the `Golang` compiler: + +```sh +sudo su - git +mkdir $HOME/local && cd $_ +``` + +> **Tip**: Check https://go.dev/dl/ +> for the latest version of `Go` +before running the next command. + +Download Go: + +```sh +wget https://storage.googleapis.com/golang/go1.18.linux-arm64.tar.gz +``` + +This will take a few seconds depending on your Internet connection speed ... + +```sh +go1.18.linux-arm64.t 59%[==========> ] 79.99M 4.92MB/s eta 12s +``` + +Once it's downloaded, extract it: + +```sh +tar -C /home/git/local -xvzf go1.18.linux-arm64.tar.gz +``` + +Set the `GOPATH` environment variable +to specify the location of our workspace. +We will set the variables in our `.bashrc` +file so they will be available every time we enter the shell. + +```sh +echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc +echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc +echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc +source $HOME/.bashrc +``` + +Note +We need to specify the `GOROOT` environment variable +since we are installing Go to a custom location. +Check that Go is properly installed: + +```sh +go version +``` + +You’ll see output that resembles the following: +```sh +go version go1.18 linux/arm64 +``` + +With `Go` and `Postgres` installed, +you're all set to install `Gogs`! + +
+ +## `Gogs`! + +Download and install Gogs +following the official instructions: +https://gogs.io/docs/installation/install_from_source + + + +```sh +# Clone the repository to the "gogs" subdirectory +git clone --depth 1 https://github.com/gogs/gogs.git gogs + +# Change working directory +cd gogs + +# Compile the main program, dependencies will be downloaded at this step + +``` + +Build the Gogs binary: + +```sh +go build -o gogs +``` + +> This may take a few minutes +> during which your console +> will appear unresponsive. + +It will produce a binary named `gogs` +in the current directory. + +Execute the binary: + +```sh +./gogs web +``` + +In your terminal, you should see output similar to the following: + +``` +2022/04/10 12:34:24 [ INFO] Gogs 0.13.0+dev +2022/04/10 12:34:24 [TRACE] Work directory: /home/git/local/gogs +2022/04/10 12:34:24 [TRACE] Custom path: /home/git/local/gogs/custom +2022/04/10 12:34:24 [TRACE] Custom config: /home/git/local/gogs/custom/conf/app.ini +2022/04/10 12:34:24 [TRACE] Log path: /home/git/local/gogs/log +2022/04/10 12:34:24 [TRACE] Build time: +2022/04/10 12:34:24 [TRACE] Build commit: +2022/04/10 12:34:24 [ INFO] Run mode: Development +2022/04/10 12:34:24 [ INFO] Listen on http://0.0.0.0:3000 +``` + +In the case of running Ubuntu as a server, +you will need the local network IP address +in order to access the Gogs server. +Run the following command in the Terminal +on the Raspberry Pi to get the IP: + +```sh +hostname -I +``` + +Output should be similar to the following: + +```sh +192.168.1.196 +``` + +Armed with this IP address, + + +

+ +## Relevant Reading / Research + ++ Install `Gogs` on Debian: +https://www.linode.com/docs/guides/install-gogs-on-debian/
+Last updated Oct 2020, some things deprecated. +But still good as a reference. \ No newline at end of file From 0b62610476e435590317ee7dbca1d44af7d287ea Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 10 Apr 2022 22:01:13 +0100 Subject: [PATCH 04/11] add nginx & systemd config to RPi Gogs setup #79 --- gogs/install-gogs-raspberrypi.md | 214 ++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 1 deletion(-) diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md index 39edb29..5ee38a8 100644 --- a/gogs/install-gogs-raspberrypi.md +++ b/gogs/install-gogs-raspberrypi.md @@ -34,6 +34,57 @@ Install Postgres on Ubuntu: ```sh sudo apt-get install -y postgresql postgresql-contrib postgresql-client libpq-dev ``` + +Open the PostgreSQL interactive terminal +to create a new database and user for Gogs: + +```sh +sudo -u postgres psql -d template1 +``` + +You should see output similar to the following: + +```sh +psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1)) +Type "help" for help. + +template1=# +``` + +Create new user for Gogs: + +```sh +CREATE USER gogs CREATEDB; +``` +You should see output similar to: + +```sh +CREATE ROLE +``` + +Set the password for user gogs: + +```sh +\password gogs +``` + +It will prompt you for the password and password confirmation. +Take note of this password, you will need it later when configuring Gogs. + +Create new database for Gogs: + +``` +CREATE DATABASE gogs OWNER gogs; +``` + + +Exit the psql terminal: + +```sh +\q +``` + +
### `git` @@ -193,6 +244,167 @@ Output should be similar to the following: ``` Armed with this IP address, +visit http://192.168.1.196:3000 +(either on the Ubuntu Pi +or on another computer +on the same network ...) + +![image](https://user-images.githubusercontent.com/194400/162982227-2ce4f772-d574-4ba7-af59-a66df1dddc60.png) + +Use the IP address for the PI as the Application URL: http://192.168.1.196:3000/ + +![image](https://user-images.githubusercontent.com/194400/162982781-18fc0a35-7bd3-405e-ba17-6dac8dcb1320.png) + +That way you can connect from other computers on your home network. + +https://gogs.io/docs/installation/configuration_and_run + + +Once configured, created a new user and repo: http://192.168.1.196:3000/nelsonic/my-awesome-repo +![image](https://user-images.githubusercontent.com/194400/163005975-2a2abefa-11a5-4085-96b8-133c8a28f587.png) + + +## Nginx + +1. Create self-signed certificate: + +Run the commands as root: +```sh +sudo su - +mkdir /root/certs && cd /root/certs +``` + +Create the self-signed certificate: +```sh +openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out MyCertificate.crt -keyout MyKey.key +``` + +Accept all the defaults for the certificate creation +this is just for use on your local network. + +2. Install Nginx + +```sh +sudo apt-get install -y nginx +``` + +If you visit +the IP address of your Ubuntu server in a web browser now, +e.g: http://192.168.1.196 +you will see the default Nginx homepage: + +![default-nginx](https://user-images.githubusercontent.com/194400/163057616-1bd02d41-342d-4fac-a6b6-8fb3e3e11134.png) + +Create the gogs site: + +```sh +sudo vi /etc/nginx/sites-available/gogs +``` + +```nginx +server { + listen 80 default_server; + server_name $http_host; + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_pass http://localhost:3000; + } +} + +server { + listen 443 ssl; + server_name example.com; + + ssl_certificate /root/certs/MyCertificate.crt; + ssl_certificate_key /root/certs/MyKey.key; + + location / { + proxy_set_header X-Real-IP $remote_addr; + proxy_pass http://localhost:3000; + } +} +``` + +Link it: +```sh +sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs +``` + +Delete the default nginx config as we don't need it: +```sh +sudo rm /etc/nginx/sites-enabled/default +``` + +Restart: +```sh +sudo systemctl restart nginx +``` + +When you refresh the page in your browser you will +now see the `gogs` page: + +![gogs-page-nginx](https://user-images.githubusercontent.com/194400/163059605-be133880-42dc-4794-920e-af6230fca4bc.png) + +## Automatic Startup with systemd + +Create the `systemd` config file: + + +```sh +sudo vi /etc/systemd/system/gogs.service +``` + +```sh +[Unit] +Description=Gogs (Go Git Service) +After=syslog.target +After=network.target +After=postgresql.service +After=nginx.service + +[Service] +Type=simple +User=git +Group=git +WorkingDirectory=/home/git/local/gogs +ExecStart=/home/git/local/gogs/gogs web +Restart=always +Environment=USER=git HOME=/home/git + +[Install] +WantedBy=multi-user.target +``` + + +Enable the systemd unit file: +``` +sudo systemctl enable gogs +``` + +Start the service: +``` +sudo systemctl start gogs +``` + +Check the status of the service: +``` +sudo systemctl status gogs +``` + +It should display the output like this: + +```sh +● gogs.service - Gogs (Go Git Service) + Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled) + Active: active (running) since Sun 2022-04-10 21:58:44 UTC; 4s ago + Main PID: 127605 (gogs) + Tasks: 7 (limit: 9021) + CGroup: /system.slice/gogs.service + └─127605 /home/git/local/gogs/gogs web + +Apr 10 21:58:44 ubuntu systemd[1]: Started Gogs (Go Git Service). +Apr 10 21:58:44 ubuntu gogs[127605]: 2022/04/10 21:58:44 [TRACE] Log mode: File (Info) +```

@@ -202,4 +414,4 @@ Armed with this IP address, + Install `Gogs` on Debian: https://www.linode.com/docs/guides/install-gogs-on-debian/
Last updated Oct 2020, some things deprecated. -But still good as a reference. \ No newline at end of file +But still good as a starting point. \ No newline at end of file From 94be16a9325fefd080af78a5fef19bc49f7e9896 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 20 Apr 2022 22:32:51 +0100 Subject: [PATCH 05/11] Connect to RPi instance via Git & REST API #79 --- README.md | 10 ++ gogs/README.md | 63 ++++++- gogs/connect-to-raspberrypi.md | 290 +++++++++++++++++++++++++++++++ gogs/install-gogs-raspberrypi.md | 15 +- 4 files changed, 369 insertions(+), 9 deletions(-) create mode 100644 gogs/connect-to-raspberrypi.md diff --git a/README.md b/README.md index 02ff9a7..de0846e 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,16 @@ infrastructure/platform providers: - Linode: [linode-setup.md](https://github.com/dwyl/learn-devops/blob/master/linode-setup.md) - DigitalOcean: [nodejs-digital-ocean-centos-dokku.md](https://github.com/dwyl/learn-devops/blob/master/nodejs-digital-ocean-centos-dokku.md) + +### `Gogs` Git Server + +We needed to run a our own `Git` server +for one of our projects. +So we deployed `Gogs` +both `locally` and to Fly.io +and documented it: +[`/gogs`]() + ### Node.js - Node.js with Dokku: diff --git a/gogs/README.md b/gogs/README.md index c9d4a99..2f30517 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -1,5 +1,5 @@
-

Learn to Deploy & Maintain a Gogs Server

+

Deploy & Maintain a Gogs Server

@@ -34,7 +34,9 @@ we are _mostly_ happy with the GitHub service. πŸ‘Œ
Except for a few annoying aspects of the interface and the occasional outage, GitHub is good. We are exploring having a **`Gogs`** server running as a -[**_hot_ backup**](https://en.wikipedia.org/wiki/Backup_site#Hot_site). +[**_hot_ backup**](https://en.wikipedia.org/wiki/Backup_site#Hot_site) +which we can use when GitHub is unavailable +or if they ever lose our data! # _Who_? πŸ€“ @@ -45,11 +47,64 @@ Please ⭐ the repo if you find it useful. Thanks! # _How_? πŸ‘©β€πŸ’» -Continue: +There are several options for running `Gogs`: +1. **Directly** on your main machine/workstation - + can be advantageous in terms of setup speed, + but clutters your main machine with a server + that requires resources + maintenance. +2. On your machine using **Docker** - provides + good isolation/separation, + reasonably fast startup times + and can be easily "killed" when no longer needed. +3. On a **_secondary_ computer** e.g. **RaspberryPi** - complete isolation, + more "hackable" and simulates production more closely. + Obviously having a second machine is a luxury + not everyone has. But we figure a + [$15](https://www.raspberrypi.com/products/raspberry-pi-zero-2-w/) + RasbperryPi Zero is not a stretch for most people doing DevOps. +4. On **3rd Party/Cloud Service** e.g. AWS or **Fly.io** - + perfect once you have decided `Gogs` is for you + and you want a Production instance for your project. + We use Fly.io because it's:
+ a) Simplicity: deploying to Fly.io is + _much_ simpler than other VPS/Cloud services (AWS!).
+ b) _Cheaper_ than an equivalent ($2/month)
+ c) Our _main_ app already runs on Fly.io + so having the `Gogs/Git` server co-located + is good for latency/speed/performance. +We chose to install `Gogs` on a **RaspberryPi** +for 3 reasons:
+a) Keeps it fully isolated on a separate machine. +Which simulates "production".
+b) Allows us to test connecting to it over a network. i.e. real world tests.
+c) Means we can run the instance long-term +and store actual (backup) data on it.
+ +There are quite a few steps for setting this up, +so we documented them in a separate doc. +See: [`/install-gogs-raspberrypi.md`]() + + + + +### Fly.io + +Once we had everything working +on the **RaspberryPi**, +we deployed a "Production" instance to Fly.io. + +See: + + + + + + +
## Reading πŸ“š @@ -57,4 +112,4 @@ Continue: Pages we read on the journey: + https://pimylifeup.com/raspberry-pi-gogs/ - ++ https://www.techrepublic.com/article/how-to-connect-to-your-local-gogs-repository-from-the-git-command-line/ \ No newline at end of file diff --git a/gogs/connect-to-raspberrypi.md b/gogs/connect-to-raspberrypi.md new file mode 100644 index 0000000..6af9410 --- /dev/null +++ b/gogs/connect-to-raspberrypi.md @@ -0,0 +1,290 @@ +
+

Connect to Local Gogs Server on RaspberryPi

+ +
+ + +> **Prerequisite**: This guide assumes you already have `Gogs` +running on a local **`RaspberryPi`**.
+If you don't, please +see: [`/install-gogs-raspberrypi.md`]() + +## Two Options: `SSH` & `REST` + +In this guide we are connecting to `Gogs` via two methods: + +1. **`SSH`** - this gives us the full `Git` experience. +2. **`REST API`** - subset of actions but `JSON` interface. +see: https://github.com/gogs/docs-api + + +## 1. Connect via `SSH` + +There are a couple of steps here. + +### 1.1 Add your Public SSH Key to `Gogs` + +> Note: this step assumes you already have an SSH Key. +> If you don't already have an SSH Key, +> follow these steps first: +> https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent + + +Copy the ***`public`*** `ssh` key on your main computer. +In my case the `id_rsa.pub` file is located at +`~/.ssh/id_rsa.pub` +on my Mac. +So to copy the contents of the file, +I run the following command: + +```sh +pbcopy < ~/.ssh/id_rsa.pub +``` + +Next, connect to the `Gogs` Server running on the RaspberryPi from my Mac, +and visit the `/user/settings/ssh` page: http://192.168.1.196/user/settings/ssh + +image + +> Note: The IP address of your RaspberryPi on your network will be different. + +Click on the (blue) **`Add Key`** button, and you will see the following input: + +image + +Once you have pasted the contents of the +`id_rsa.pub` file into the **`Content`** textarea field, +click on the (_green_) **`Add Key`** button below the input. + + +You should see a message confirming that the +"**New SSH key** was added successfully!" +e.g: + +image + + + +### 1.2 Clone a Repository + +During the `Gogs` server setup, +I had previously created a test repository: +http://192.168.1.196/nelsonic/my-awesome-repo + +image + +In the UI there is a link you can copy to clone the repository, +annoyingly the link has a base URL of `localhost` +i.e. `git@localhost:nelsonic/my-awesome-repo.git` + +If we replace the `localhost` with the IP address of the RaspberryPi +in our case `192.168.1.196` then the `git clone` command will work: + +``` +git clone git@192.168.1.196:nelsonic/my-awesome-repo.git +``` + +You will see output similar to the following: + +```sh +Cloning into 'my-awesome-repo'... +remote: Enumerating objects: 8, done. +remote: Counting objects: 100% (8/8), done. +remote: Compressing objects: 100% (6/6), done. +remote: Total 8 (delta 1), reused 0 (delta 0) +Receiving objects: 100% (8/8), 6.86 KiB | 6.86 MiB/s, done. +Resolving deltas: 100% (1/1), done. +``` + +Change into the repo directory e.g: + +```sh +$ cd my-awesome-repo +$ ls + +LICENSE README.md +``` + + +### 1.3 Make Changes to the `README.md` of the Repo + +Open the `README.md` file in your editor, +e.g: + +```sh +vi README.md +``` + + +image + +Make a basic change/addition to `README.md` +and save the file. + + +### 1.4 Commit and Push the Change + +```sh +git add . && git commit -m 'update README.md on mac' +``` + +You should see output similar to: + +```sh +[master be03eb4] update README.md on mac + 1 file changed, 3 insertions(+), 1 deletion(-) +``` + +Push the changes to the `Gogs` server: + +```sh +git push +``` + +You should see output similar to the following: + +```sh +Enumerating objects: 5, done. +Counting objects: 100% (5/5), done. +Delta compression using up to 8 threads +Compressing objects: 100% (3/3), done. +Writing objects: 100% (3/3), 315 bytes | 315.00 KiB/s, done. +Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 +To 192.168.1.196:nelsonic/my-awesome-repo.git + 623a46d..be03eb4 master -> master +``` + +Visit the repo in your web browser: +http://192.168.1.196/nelsonic/my-awesome-repo + +confirm that the change was persisted to the `Gogs` server. + +gogs-update-readme-file-on-mac + +Success! + +
+ + +## 2. Connect via `REST API` (`HTTPS`) + +The second way of connecting to `Gogs` is via the REST API. +Here we will be following and expanding on the official docs: +https://github.com/gogs/docs-api + +Visit: `/user/settings/applications` of your `Gogs` instance, +e.g: +http://192.168.1.196/user/settings/applications + +gogs-create-access-token + +And click on **`Generate New Token`**. + +Then input the name of your token, +in case you end up with multiple tokens. + +gogs-generate-token + +Token generated: + +image + +My access token is: +**`04b3e63399da5e04258bf56ede5ad7646f1cda35`**. +We will be using this below. Make a note of yours. + +> Don't worry, this is only valid for my test instance on my local RaspberryPi. +By the time you read this I will have already reset it and the token will be invalid. + + +With this access token in-hand we can now run `cURL` commands +to test the REST API, e.g: + +```sh +curl -u "nelsonic" 'http://192.168.1.196/api/v1/users/unknwon/tokens' +``` + +Response: + +```sh +[{"name":"Mac\u003c-\u003eRPI","sha1":"04b3e63399da5e04258bf56ede5ad7646f1cda35"}]% +``` + +> OK, I regret naming my token **`Mac<->RPI`** now ... πŸ™„ +> But you get the idea. It works! + + +```sh +curl 'http://192.168.1.196/api/v1/repos/nelsonic/my-awesome-repo?token=04b3e63399da5e04258bf56ede5ad7646f1cda35' +``` + +```json +{ + "id": 1, + "owner": { + "id": 1, + "username": "nelsonic", + "login": "nelsonic", + "full_name": "", + "email": "nelson@gmail.com", + "avatar_url": "https://secure.gravatar.com/avatar/f937427bea8db9d88608a54b2b803f1a?d=identicon" + }, + "name": "my-awesome-repo", + "full_name": "nelsonic/my-awesome-repo", + "description": "test repo", + "private": false, + "fork": false, + "parent": null, + "empty": false, + "mirror": false, + "size": 49152, + "html_url": "http://localhost:3000/nelsonic/my-awesome-repo", + "ssh_url": "git@localhost:nelsonic/my-awesome-repo.git", + "clone_url": "http://localhost:3000/nelsonic/my-awesome-repo.git", + "website": "", + "stars_count": 1, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 1, + "default_branch": "master", + "created_at": "2022-04-12T16:06:13Z", + "updated_at": "2022-04-12T16:06:13Z", + "permissions": { + "admin": true, + "push": true, + "pull": true + } +} +``` + +curl -I http://192.168.1.196/api/v1/repos/nelsonic/my-awesome-repo?token=04b3e63399da5e04258bf56ede5ad7646f1cda35 + +``` +curl -H "Authorization: token 04b3e63399da5e04258bf56ede5ad7646f1cda35" http://192.168.1.196/api/v1/repos -H "Accept: application/json" +``` + +```sh +/api/v1/repos/:username/:reponame/raw/:ref/:path +``` + +Example: + +```sh +curl 'http://192.168.1.196/api/v1/repos/nelsonic/my-awesome-repo/raw/master/README.md?token=04b3e63399da5e04258bf56ede5ad7646f1cda35' +``` + +Response: + +```md +# My Awesome Repo! + +This is my Markdown editor. +It totally works in the browser. + +Updated in Vim on Mac. +``` + + +

+ +[![HitCount](http://hits.dwyl.com/dwyl/learn-devops-gogs-connect-rpi.svg)](http://hits.dwyl.com/dwyl/learn-devops-gogs) \ No newline at end of file diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md index 5ee38a8..e69e0b5 100644 --- a/gogs/install-gogs-raspberrypi.md +++ b/gogs/install-gogs-raspberrypi.md @@ -1,4 +1,4 @@ -# Install Gogs on Raspberry Pi +# Install `Gogs` on RaspberryPi This guide follows and expands on the official **`Gogs`** @@ -9,16 +9,21 @@ Our objective is to capture _all_ the steps required so that _anyone_ can follow along and replicate our _exact_ result. +> _If you get stuck along the way, +> please don't suffer in silence! +> Ask for help_; +> [**open an issue**!](https://github.com/dwyl/learn-devops/issues) ## Prerequisites -Ensure you have a working Raspberry Pi running +Ensure you have a working RaspberryPi running Ubuntu: https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview > We are using Ubuntu because it's _ubiquitous_ -> and will help with deployment to Cloud/VPS later +> and will help with both Continuous Integration +> and deployment to Cloud/VPS later > so getting it working on the Pi is a good first step. βœ… @@ -112,7 +117,7 @@ sudo adduser --disabled-login --gecos 'Gogs' git
-### `Go`s +### `Go lang` We are going to compile `gogs` from source so we need the `Golang` compiler: @@ -156,7 +161,7 @@ echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc source $HOME/.bashrc ``` -Note +**Note**: We need to specify the `GOROOT` environment variable since we are installing Go to a custom location. Check that Go is properly installed: From 65140867470f30d60bdef0efe5cd178dd68591ec Mon Sep 17 00:00:00 2001 From: nelsonic Date: Sun, 24 Apr 2022 00:59:11 +0100 Subject: [PATCH 06/11] update gogs deployment #79 --- README.md | 6 ++++++ gogs/README.md | 19 ++++++++++++++----- gogs/connect-to-raspberrypi.md | 3 ++- gogs/install-gogs-raspberrypi.md | 4 +++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index de0846e..a420c59 100644 --- a/README.md +++ b/README.md @@ -180,3 +180,9 @@ As you can see, from the pricing, the _resources_ do offer value-for money once the project's database goes above a certain size. --> +
+Thanks for learning with us! +Your feedback/questions is always welcome. + +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/learn-devops/issues) +[![HitCount](http://hits.dwyl.com/dwyl/learn-devops.svg)](http://hits.dwyl.com/dwyl/learn-devops) \ No newline at end of file diff --git a/gogs/README.md b/gogs/README.md index 2f30517..a3c87a4 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -9,7 +9,7 @@ for complete beginners.

-[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/learn-travis/issues) +[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/learn-devops/issues) [![HitCount](http://hits.dwyl.com/dwyl/learn-devops-gogs.svg)](http://hits.dwyl.com/dwyl/learn-devops-gogs)
@@ -88,14 +88,23 @@ There are quite a few steps for setting this up, so we documented them in a separate doc. See: [`/install-gogs-raspberrypi.md`]() +Once we had setup the `Gogs` server on the `RPi` +with `nginx` and `systemd` to auto-boot +whenever we restart the `RPi`, +we tested connecting to `Gogs` on the `RPi` +and documented the steps: +[`/connect-to-raspberrypi.md`]() - +Once we confirmed that everything was working +on the local **`RaspberryPi`**, +we felt confident to deploy to Fly.io ### Fly.io -Once we had everything working -on the **RaspberryPi**, -we deployed a "Production" instance to Fly.io. +Once we had everything working & tested +on the **`RaspberryPi`**, +we felt confident +so we deployed a "Production" instance to Fly.io. See: diff --git a/gogs/connect-to-raspberrypi.md b/gogs/connect-to-raspberrypi.md index 6af9410..3e66580 100644 --- a/gogs/connect-to-raspberrypi.md +++ b/gogs/connect-to-raspberrypi.md @@ -1,5 +1,6 @@
-

Connect to Local Gogs Server on RaspberryPi

+ +# _Connect_ to Local Gogs Server on RaspberryPi
diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md index e69e0b5..b4a6f47 100644 --- a/gogs/install-gogs-raspberrypi.md +++ b/gogs/install-gogs-raspberrypi.md @@ -419,4 +419,6 @@ Apr 10 21:58:44 ubuntu gogs[127605]: 2022/04/10 21:58:44 [TRACE] Log mode: File + Install `Gogs` on Debian: https://www.linode.com/docs/guides/install-gogs-on-debian/
Last updated Oct 2020, some things deprecated. -But still good as a starting point. \ No newline at end of file +But still good as a starting point. + +[![HitCount](http://hits.dwyl.com/dwyl/learn-devops-gogs-rpi-setup.svg)](http://hits.dwyl.com/dwyl/learn-devops-gogs) \ No newline at end of file From 5520e26b25d3585488f8e1cd3099dfe0b81c2bfc Mon Sep 17 00:00:00 2001 From: nelsonic Date: Mon, 25 Apr 2022 00:24:14 +0100 Subject: [PATCH 07/11] add link to https://github.com/dwyl/gogs-server in /gogs --- gogs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gogs/README.md b/gogs/README.md index a3c87a4..aadad3e 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -106,7 +106,7 @@ on the **`RaspberryPi`**, we felt confident so we deployed a "Production" instance to Fly.io. -See: +See: https://github.com/dwyl/gogs-server From 2c5854351c23fa40be22999d4d07b54354c9b434 Mon Sep 17 00:00:00 2001 From: Nelson <194400+nelsonic@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:19:24 +0100 Subject: [PATCH 08/11] Update link to install-gogs-raspberrypi.md in gogs/README.md Co-authored-by: Simon --- gogs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gogs/README.md b/gogs/README.md index aadad3e..5ee2f74 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -86,7 +86,7 @@ and store actual (backup) data on it.
There are quite a few steps for setting this up, so we documented them in a separate doc. -See: [`/install-gogs-raspberrypi.md`]() +See: [`/install-gogs-raspberrypi.md`](./install-gogs-raspberrypi.md) Once we had setup the `Gogs` server on the `RPi` with `nginx` and `systemd` to auto-boot From 96d1894eca3d116f580c43ad044dc9683a68929c Mon Sep 17 00:00:00 2001 From: Nelson <194400+nelsonic@users.noreply.github.com> Date: Wed, 27 Apr 2022 11:19:40 +0100 Subject: [PATCH 09/11] Update link to connect-to-raspberrypi.md in gogs/README.md Co-authored-by: Simon --- gogs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gogs/README.md b/gogs/README.md index 5ee2f74..60804ca 100644 --- a/gogs/README.md +++ b/gogs/README.md @@ -93,7 +93,7 @@ with `nginx` and `systemd` to auto-boot whenever we restart the `RPi`, we tested connecting to `Gogs` on the `RPi` and documented the steps: -[`/connect-to-raspberrypi.md`]() +[`/connect-to-raspberrypi.md`](./connect-to-raspberrypi.md) Once we confirmed that everything was working on the local **`RaspberryPi`**, From 0efdfa25840dc3455bca5e6e623c9d1bcb4c9478 Mon Sep 17 00:00:00 2001 From: Nelson <194400+nelsonic@users.noreply.github.com> Date: Wed, 27 Apr 2022 13:12:43 +0100 Subject: [PATCH 10/11] Fix grammar in postgres section Co-authored-by: Simon --- gogs/install-gogs-raspberrypi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md index b4a6f47..76bced8 100644 --- a/gogs/install-gogs-raspberrypi.md +++ b/gogs/install-gogs-raspberrypi.md @@ -30,7 +30,7 @@ https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overvi ### **`Postgres`** The default DB for **`Gogs`** -is be **`MySQL`**, +is **`MySQL`**, but we prefer **`Postgres`**. Install Postgres on Ubuntu: From 60b330b6d8b5c5582d6757c387469dc2383a52ec Mon Sep 17 00:00:00 2001 From: Nelson <194400+nelsonic@users.noreply.github.com> Date: Wed, 27 Apr 2022 13:13:00 +0100 Subject: [PATCH 11/11] Fix grammar by adding a comma to break sentence. Co-authored-by: Simon --- gogs/install-gogs-raspberrypi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gogs/install-gogs-raspberrypi.md b/gogs/install-gogs-raspberrypi.md index 76bced8..f62d1cf 100644 --- a/gogs/install-gogs-raspberrypi.md +++ b/gogs/install-gogs-raspberrypi.md @@ -284,7 +284,7 @@ Create the self-signed certificate: openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out MyCertificate.crt -keyout MyKey.key ``` -Accept all the defaults for the certificate creation +Accept all the defaults for the certificate creation, this is just for use on your local network. 2. Install Nginx