-
Notifications
You must be signed in to change notification settings - Fork 8
94 lines (92 loc) · 4 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Build projects-bot
on:
push:
jobs:
format-lint-check:
name: "Format & lint check"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npm run format:check
- run: npm run lint
build:
name: "Build"
runs-on: ubuntu-latest
needs: ["format-lint-check"]
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/projects-bot' ) }}
platforms: linux/amd64
file: Dockerfile
tags: |
ghcr.io/csesoc/projects-discord-bot:${{ github.sha }}
ghcr.io/csesoc/projects-discord-bot:latest
labels: ${{ steps.meta.outputs.labels }}
deploy:
name: Deploy (CD)
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/projects-bot' ) }}
concurrency: production
environment:
name: production (projects-bot)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: csesoc/deployment
token: ${{ secrets.GH_TOKEN }}
- name: Install yq - portable yaml processor
uses: mikefarah/yq@v4.44.6
- name: Determine file to update
id: get_manifest
env:
BRANCH_NAME: ${{ github.ref }}
run: |
if [ "$BRANCH_NAME" = "refs/heads/projects-bot" ]; then
echo "MANIFEST=apps/projects/bot/ptb/deploy.yml" >> $GITHUB_OUTPUT
echo "DEPLOYMENT=ptb" >> $GITHUB_OUTPUT
elif [ "$BRANCH_NAME" = "refs/heads/develop" ]; then
echo "MANIFEST=apps/projects/bot/qa/deploy.yml" >> $GITHUB_OUTPUT
echo "DEPLOYMENT=qa" >> $GITHUB_OUTPUT
else
exit 1
fi
- name: Update deployment
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config user.name "CSESoc CD"
git config user.email "technical@csesoc.org.au"
git checkout -b update/projects-bot/${{ github.sha }}
yq -i '.spec.template.spec.containers[0].image = "ghcr.io/csesoc/projects-discord-bot:${{ github.sha }}"' ${{ steps.get_manifest.outputs.MANIFEST }}
git add .
git commit -m "feat(projects-bot/${{ steps.get_manifest.outputs.DEPLOYMENT }}): update images"
git push -u origin update/projects-bot/${{ github.sha }}
gh pr create --title "feat(projects-bot/${{ steps.get_manifest.outputs.DEPLOYMENT }}): update images" --body "Updates the images for the projects-bot deployment to commit csesoc/discord-bot@${{ github.sha }}." > URL
gh pr merge $(cat URL) --squash -d