Skip to content

Commit 56e491a

Browse files
techknowlogickalexellis
authored andcommitted
Update Gitea Bot blog post with additional details
Signed-off-by: Matti R <[email protected]>
1 parent 987ae0d commit 56e491a

File tree

1 file changed

+74
-32
lines changed

1 file changed

+74
-32
lines changed

_posts/2021-01-31-gitea-faas.md

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ In this post we will walk through building a simple bot to label pull-requests.
2323

2424
## Pre-requisites
2525

26-
For the purposes of this guide we'll create a local virtual machine and install faasd on it, but these instructions can be extended to use a Digital Ocean Droplet, or even a Raspberry Pi. The tutorial should take you less than 15-30 minutes to try.
26+
For the purposes of this guide we'll create a local virtual machine and install faasd on it, but these instructions can be extended to use TLS on an [Digital Ocean Droplet](https://www.openfaas.com/blog/faasd-tls-terraform/), or even a [Raspberry Pi](https://blog.alexellis.io/faasd-for-lightweight-serverless/). The tutorial should take you less than 15-30 minutes to try.
2727

28-
### Create a Virtual Machine and install faasd
28+
* https://www.openfaas.com/blog/faasd-tls-terraform/
29+
* https://blog.alexellis.io/faasd-for-lightweight-serverless/
30+
31+
### Create a Virtual Machine
2932

3033
[Multipass](https://multipass.run) is a lightweight virtual machine runner, think docker-compose but for ubuntu virtual machines. We'll use this to get a virtual machine with faasd up and running quickly.
3134

@@ -35,20 +38,10 @@ For the purposes of this guide we'll create a local virtual machine and install
3538
brew install multipass
3639
## or, on Linux, you can install using the snap command
3740
snap install multipass
38-
39-
# Get VM Bootstrap instructions
40-
wget https://raw.githubusercontent.com/openfaas/faasd/master/cloud-config.txt
41-
42-
# Generate a key for SSH-ing into your VM
43-
ssh-keygen -t rsa -b 4096 -C "faasd" -f $PWD/faasd_ssh
44-
45-
# Add your local key to the cloud-init file
46-
awk "NR==4 {\$0=\" - $(cat faasd_ssh.pub)\"} { print }" cloud-config.txt > tmp
47-
mv tmp cloud-config.txt
41+
# For windows, you'll need to use the installer found on multipass.run
4842

4943
# Run a local VM
5044
multipass launch \
51-
--cloud-init cloud-config.txt \
5245
--name faasd
5346

5447
# Verify your VM has been started
@@ -57,9 +50,22 @@ multipass info faasd
5750

5851
### Connect faas-cli to your faasd install
5952

60-
Now that faasd is up and running, we'll need to login into the gateway with the `faas-cli`.
53+
Now that faasd is up and running, we'll need to install faasd, and login into the gateway with the `faas-cli`.
6154

6255
```bash
56+
# Connect to VM
57+
multipass exec faasd bash
58+
59+
# Clone
60+
git clone https://github.com/openfaas/faasd.git
61+
62+
# Install faasd
63+
cd faasd
64+
sh hack/install.sh
65+
66+
# Now exit the VM
67+
exit
68+
6369
# Install faas-cli on your host machine
6470
curl -sSLf https://cli.openfaas.com | sh
6571

@@ -81,43 +87,79 @@ faas-cli list
8187
Next we'll need to install Gitea it up and running. This example uses the bleeding edge nightly version, but for production use you may wish to use the current stable version of Gitea.
8288

8389
```bash
84-
# SSH into your VM
85-
ssh -i ./faasd_ssh ubuntu@$VM_IP
90+
# Connect to your VM as root
91+
multipass exec faasd sudo bash
8692

87-
# Download Gitea nightly version
88-
wget https://dl.gitea.io/gitea/master/gitea-master-linux-amd64
89-
mv gitea-master-linux-amd64 gitea
90-
chmod +x gitea
91-
92-
# Create base Gitea configuration
93-
cat >/home/ubuntu/app.ini <<EOL
94-
RUN_USER = ubuntu
93+
# Add Gitea configuration
94+
mkdir -p /var/snap/gitea/common/{conf,data}/
95+
cat >/var/snap/gitea/common/conf/app.ini <<EOL
96+
RUN_USER=root
9597
[server]
9698
DOMAIN = $(hostname -I | awk '{print$1}')
9799
DISABLE_SSH=true
98100
[database]
99101
DB_TYPE = sqlite3
100-
PATH = /home/ubuntu/gitea.db
102+
PATH = /var/snap/gitea/common/data/gitea.db
101103
[security]
102104
INSTALL_LOCK = true
103105
[oauth2]
104106
ENABLE=false
105107
EOL
106108

109+
# Use snap to install Gitea
110+
snap install gitea
111+
107112
# Create Gitea database
108-
./gitea --config $(pwd)/app.ini migrate
113+
gitea migrate
109114

110115
# Create a Gitea user
111116
export GITEA_PASSWORD="TEMPOPENFAASPASSWORD"
112-
./gitea --config $(pwd)/app.ini admin user create --admin --name gitea_admin --password $GITEA_PASSWORD --email [email protected]
117+
gitea admin create-user --admin --name gitea_admin --password $GITEA_PASSWORD --email [email protected]
113118

114-
# Run Gitea
115-
screen -d -m ./gitea --config $(pwd)/app.ini web
116-
117-
# Exit out of the SSH connection
119+
# Exit out of your VM
118120
exit
119121
```
120122

123+
### Optionally install OpenFaaS and Gitea on a Kubernetes Cluster
124+
125+
`faasd` is great for single node installations, but if you are planning on scaling up to multiple servers you can install OpenFaaS and Gitea on a kubernetes cluster.
126+
127+
```bash
128+
# Get arkade, and move it to $PATH
129+
curl -sLS https://dl.get-arkade.dev | sh
130+
sudo mv arkade /usr/local/bin/
131+
132+
# Fetch Kubernetes tools to run locally
133+
arkade get kind
134+
135+
# OpenFaaS CLI
136+
arkade get faas-cli
137+
138+
# Create a cluster - if you already have a kubernetes cluster somewhere you can skip this step
139+
kind create cluster
140+
141+
# Install OpenFaaS
142+
arkade install openfaas
143+
144+
# Install Gitea
145+
arkade install gitea
146+
```
147+
148+
Next, you'll need to portforward both Gitea, and OpenFaaS, as well as login into the OpenFaaS gateway with faas-cli
149+
150+
```bash
151+
# Forward the OpenFaaS gateway to your machine
152+
kubectl rollout status -n openfaas deploy/gateway
153+
kubectl port-forward -n openfaas svc/gateway 8080:8080 &
154+
155+
# If basic auth is enabled, you can now log into your gateway:
156+
PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath="{.data.basic-auth-password}" | base64 --decode; echo)
157+
echo -n $PASSWORD | faas-cli login --username admin --password-stdin
158+
159+
# Forward the Gitea application to your machine
160+
kubectl -n default port-forward svc/gitea-http 3000:3000 &
161+
```
162+
121163
### Sign into Gitea and create test repo
122164

123165
Finally after Gitea is installed, we'll need to verify the installation. To do this we will open up the Gitea interface in the browser and login into it.
@@ -346,4 +388,4 @@ Now that we’ve seen how to create a simple bot using faasd, from here we can b
346388

347389
### Taking it further
348390

349-
For a production ready OpenFaaS function that supports automation in Gitea you can view the [Gitea/Buildkite connector](https://github.com/techknowlogick/gitea-buildkite-connector).
391+
For a production ready OpenFaaS function that supports automation in Gitea you can view the [Gitea/Buildkite connector](https://github.com/techknowlogick/gitea-buildkite-connector), or build upon the above [LGTMBot function](https://github.com/techknowlogick/faas-lgtmbot).

0 commit comments

Comments
 (0)