From 05a442f6908b38fac6a3edadcb5c486c5f25438c Mon Sep 17 00:00:00 2001 From: Adam McCartney Date: Mon, 19 Dec 2022 13:25:30 +0100 Subject: [PATCH 1/3] Include additional variable for host We should also template the hostname, i.e. remove the previously hardcoded values. --- deployments/pacman-deployment.yaml | 2 +- ingress/ingress.txt.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/deployments/pacman-deployment.yaml b/deployments/pacman-deployment.yaml index 7b98e6a..b4a768e 100644 --- a/deployments/pacman-deployment.yaml +++ b/deployments/pacman-deployment.yaml @@ -17,7 +17,7 @@ spec: name: pacman spec: containers: - - image: adlsregistrysbx.azurecr.io/tutorials/pacman:latest + - image: ghcr.io/austriandatalab/pacman:latest name: pacman ports: - containerPort: 8080 diff --git a/ingress/ingress.txt.yaml b/ingress/ingress.txt.yaml index 395b1e6..78af45d 100644 --- a/ingress/ingress.txt.yaml +++ b/ingress/ingress.txt.yaml @@ -9,7 +9,7 @@ metadata: spec: ingressClassName: nginx rules: - - host: ingress-$pacman.k8s.dev.austrianopensciencecloud.org + - host: ingress-$pacman.$host http: paths: - backend: @@ -22,4 +22,4 @@ spec: #tls: #- hosts: # - ingress-$pacman.k8s.dev.austrianopensciencecloud.org - # secretName: $pacman-ingress-tls \ No newline at end of file + # secretName: $pacman-ingress-tls From 37714d92801a15a3caa9dcbe13443bd62af424d8 Mon Sep 17 00:00:00 2001 From: Adam McCartney Date: Mon, 19 Dec 2022 14:11:19 +0100 Subject: [PATCH 2/3] Replace hardcoded values in shell scripts Include instructions to set up an environment file locally. --- README.md | 57 ++++++++++++++++++++++++++++++++------------- pacman-install.sh | 5 +--- pacman-uninstall.sh | 5 ++-- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a98f559..5fdfc38 100644 --- a/README.md +++ b/README.md @@ -43,36 +43,61 @@ This was taken from https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kuber You have a valid student user and have logged into RancherUI https://rancher.k8s.dev.austrianopensciencecloud.org/ -## Deployment -### Note your username and path to kubeconf file -your user starts with 'u-' and you can run in the RacherUI: + +Clone this git repository and change into the pacman directory + ```bash -kubectl get all +git clone git@github.com:AustrianDataLAB/pacman.git +cd pacman ``` -that ll tell you, that your user 'u-***' doesnt have rights to see something. Copy this string! -Download the kubeconfig file from the RancherUI, top right and save it somewhere on your laptop. +## Deployment + +You will need to set three environment variables in your local environment in +order for the shell scripts to run correctly, and for the pacman application to +be deployed to the cluster. -```bash -export KUBECONFIG=~/Downloads/local-2.yaml -export pacman='u-r6hs89045r2f' +1. `$KUBECONFIG`, the absolute path to the kube config file for the cluster. + Download from the RancherUI and save locally. +2. `$pacman`, the target [namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) + where the app will be deployed. Appears in the RancherUI, in dropdown menu + on the top right under "Only User Namespaces". Follows the form `u-XXXXX` + where `XXXXX` are random characters. +3. `$host`, the DNS hostname for the cluster. In the url: + "https://rancher.caas-0005.dev.austrianopencloudcommunity.org" + the DNS hostname is: "caas-0005.dev.austrianopencloudcommunity.org" + +### Create .env file + +Modify the values as they apply to you and save them to a file named `.env` +```bash +cat < .env +export KUBECONFIG=/home/user/k8s/clusters/caas-0005.dev/kubeconfig.yaml +export pacman=u-XXXXXX +export host=caas-0005.dev.austrianopencloudcommunity.org +EOF ``` + + ### Using a Script for installation -Clone repo, checkout branch=`main` -Then: run ```chmod +X pacman-install.sh``` and then run file ```./pacman-install.sh``` + +Make the script executable, source the environment file and run the script. + ```bash -git clone git@github.com:entlein/pacman.git -chmod +X pacman-install.sh +chmod +x pacman-install.sh +source .env ./pacman-install.sh ``` - - #### Uninstall using a Script + Run file `./pacman-uninstall.sh`. This will delete all objects created by `./pacman-install.sh` -Alternatively, run `./pacman-uninstall.sh keeppvc`. This will delete all objects except for the pacman namespace and the persistent volume claim. You can use this to demonstrate persistence of the MongoDB data by installing, playing a game and recording a high score, then unininstalling with the `keeppvc` argument. You can then run the installation again and the high score will persist. +Alternatively, run `./pacman-uninstall.sh keeppvc`. This will delete all objects except for +the pacman namespace and the persistent volume claim. You can use this to demonstrate persistence +of the MongoDB data by installing, playing a game and recording a high score, then unininstalling +with the `keeppvc` argument. You can then run the installation again and the high score will persist. #### Note of caution: Cert manager will only sign very few official certificates per 168 hrs Before adding the ingress/cert, make sure you understand what that does and that you know how to keep your certificate 'safe' diff --git a/pacman-install.sh b/pacman-install.sh index b1a6a0e..fb243e4 100755 --- a/pacman-install.sh +++ b/pacman-install.sh @@ -1,8 +1,5 @@ #!/bin/sh -#Taken from this blog: https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-9 -#Please modify the next two lines with your values -export KUBECONFIG=~/Downloads/local-3.yaml -export pacman='u-rXXXX' +# Taken from this blog: https://vzilla.co.uk/vzilla-blog/building-the-home-lab-kubernetes-playground-part-9 echo "Installing your PacMan app on K8s" envsubst < persistentvolumeclaim/mongo-pvc.txt.yaml > persistentvolumeclaim/mongo-pvc.yaml diff --git a/pacman-uninstall.sh b/pacman-uninstall.sh index bb49e0f..cffed9b 100755 --- a/pacman-uninstall.sh +++ b/pacman-uninstall.sh @@ -1,6 +1,5 @@ #!/bin/bash -export KUBECONFIG=~/Downloads/local-3.yaml -export pacman='u-rXXXXXXX' + #kubectl delete -n $pacman -f security/rbac.yaml kubectl delete -n $pacman -f security/secret.yaml kubectl delete -n $pacman -f deployments/mongo-deployment.yaml @@ -22,3 +21,5 @@ echo "cleaning up your files" rm persistentvolumeclaim/mongo-pvc.yaml rm security/secret.yaml rm ingress/ingress.yaml + + From 7cf7f3f7492e791678355d3f8b1679be3a072d87 Mon Sep 17 00:00:00 2001 From: Adam McCartney Date: Mon, 19 Dec 2022 14:19:40 +0100 Subject: [PATCH 3/3] Add rules to generate tags for image --- .github/workflows/publish-image.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml index 94eefd2..142db07 100644 --- a/.github/workflows/publish-image.yml +++ b/.github/workflows/publish-image.yml @@ -29,6 +29,12 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=ref,event=pr + type=match,pattern=\d.\d.\d.* + type=sha - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc