Skip to content

Commit a0a4623

Browse files
Ani1357j-zimnowoda
andauthored
ci: added automatic deployment to dev for commits to main (#2047)
Co-authored-by: Jehoszafat Zimnowoda <[email protected]>
1 parent 94b056f commit a0a4623

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

.github/workflows/main.yml

+11-13
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ env:
1111
REPO: linode/apl-core
1212
DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_LINODEBOT_TOKEN }}
1313
DOCKER_USERNAME: ${{ vars.DOCKERHUB_LINODEBOT_USERNAME }}
14+
DEV_KUBECONFIG_64: ${{ secrets.DEV_KUBECONFIG }}
15+
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
16+
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
17+
COMMIT_SHA: ${{ github.sha }}
1418

1519
jobs:
1620
build-test-cache:
1721
if: (!contains(github.event.head_commit.message, 'ci skip') && !startsWith(github.ref, 'refs/tags/') && !github.event.act)
1822
runs-on: ubuntu-22.04
19-
env:
20-
COMMIT_MSG: ${{ github.event.head_commit.message }}
21-
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
22-
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
2323
steps:
2424
- name: Set env
2525
run: |
@@ -51,9 +51,6 @@ jobs:
5151
needs: build-test-cache
5252
if: always() && ((contains(needs.build-test-cache.result, 'success') && !contains(needs.integration.outputs.started, 'true')) || (contains(needs.integration.result, 'success'))) && !github.event.act && github.actor != 'dependabot[bot]'
5353
runs-on: ubuntu-22.04
54-
env:
55-
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
56-
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
5754
steps:
5855
- name: Push to docker hub
5956
run: |
@@ -68,15 +65,20 @@ jobs:
6865
- name: Show me the logic
6966
run: |
7067
echo github.ref == ${{ github.ref }}
68+
deploy-to-dev:
69+
needs: push-to-docker
70+
if: always() && (startsWith(github.ref, 'refs/heads/main')) && !github.event.act
71+
runs-on: ubuntu-22.04
72+
steps:
73+
- name: Deploy to dev
74+
run: ci/scripts/trigger_dev.sh
7175

7276
release:
7377
needs: push-to-docker
7478
if: always() && (startsWith(github.ref, 'refs/heads/releases/') || startsWith(github.ref, 'refs/heads/main')) && startsWith(github.event.head_commit.message, 'chore(release)') && !github.event.act
7579
runs-on: ubuntu-22.04
7680
env:
7781
COMMIT_MSG: ${{ github.event.head_commit.message }}
78-
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
79-
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
8082
steps:
8183
- name: Checkout
8284
uses: actions/checkout@v4
@@ -120,10 +122,6 @@ jobs:
120122
container:
121123
image: linode/apl-tools:v2.8.2
122124
options: --user 0 # See https://docs.github.com/en/actions/sharing-automations/creating-actions/dockerfile-support-for-github-actions#user
123-
env:
124-
COMMIT_MSG: ${{ github.event.head_commit.message }}
125-
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
126-
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
127125
steps:
128126
- name: Checkout
129127
uses: actions/checkout@v4

ci/scripts/trigger_dev.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#! /bin/bash
2+
# This script is used to deploy the latest changes merged on main to the dev environment.
3+
4+
set -e
5+
6+
echo "Decode and set the Kubernetes configuration for the dev environment"
7+
if [ -z "$KUBECONFIG" ]; then
8+
echo $DEV_KUBECONFIG_64 | base64 -d >.kubeconfig
9+
export KUBECONFIG=$(pwd)/.kubeconfig
10+
fi
11+
12+
echo "Restart deployments platform deployments"
13+
kubectl -n otomi rollout restart deployment/otomi-api
14+
kubectl -n otomi rollout restart deployment/otomi-console
15+
kubectl rollout restart deployment -n apl-harbor-operator apl-harbor-operator
16+
kubectl rollout restart deployment -n apl-keycloak-operator apl-keycloak-operator
17+
kubectl rollout restart deployment -n apl-gitea-operator apl-gitea-operator
18+
kubectl rollout restart deployment -n otomi-operator otomi-operator
19+
20+
echo "Extract Gitea username, password, and values repo git url"
21+
export USERNAME=$(kubectl get secret -n otomi-pipelines gitea-credentials -ojsonpath='{.data.username}' | base64 -d)
22+
export PASSWORD=$(kubectl get secret -n otomi-pipelines gitea-credentials -ojsonpath='{.data.password}' | base64 -d)
23+
export URL=$(kubectl get ingress nginx-team-admin-platform-public-open -n istio-system -o json | jq -r '.spec.rules[] | select(.host | startswith("gitea")) | .host')
24+
25+
if [ -n "$BOT_USERNAME" ] && [ -n "$BOT_EMAIL" ]; then
26+
echo "Configure Git user details for committing changes"
27+
git config --global user.name "$BOT_USERNAME"
28+
git config --global user.email "$BOT_EMAIL"
29+
fi
30+
31+
echo "Clone the values repository using the decoded credentials"
32+
git clone --depth 2 https://$USERNAME:$PASSWORD@$URL/otomi/values.git 2>/dev/null
33+
cd values
34+
35+
echo "Create an empty commit to trigger the pipeline and push it to the main branch"
36+
git commit --allow-empty -m "Triggering pipeline for ${COMMIT_SHA}"
37+
git push origin main
38+
echo "Successfully triggered the pipeline for the dev environment"

0 commit comments

Comments
 (0)