-
-
Notifications
You must be signed in to change notification settings - Fork 71
75 lines (64 loc) · 2.24 KB
/
deploy.yml
File metadata and controls
75 lines (64 loc) · 2.24 KB
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
name: Build and Deploy
on:
push:
branches: ["master", "deploy"]
paths-ignore:
- '.github/**'
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Lowercase Repo Name
id: repo_lc
run: echo "repo=${GITHUB_REPOSITORY,,}" >> ${GITHUB_OUTPUT}
- name: Check Image Build Needed
id: check-image
run: |
if docker manifest inspect ghcr.io/${{ steps.repo_lc.outputs.repo }}:${{ github.sha }} > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Build and Push Image
if: steps.check-image.outputs.exists != 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
ghcr.io/${{ steps.repo_lc.outputs.repo }}:latest
ghcr.io/${{ steps.repo_lc.outputs.repo }}:${{ github.sha }}
deploy-sync:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Determine Target Environment
id: env-check
run: |
if [[ "${{ github.ref_name }}" == "deploy" ]]; then
echo "target=production" >> $GITHUB_OUTPUT
else
echo "target=staging" >> $GITHUB_OUTPUT
fi
- name: Update Manifest in Infra Repo
run: |
git clone https://x-access-token:${{ secrets.INFRA_REPO_TOKEN }}@github.com/FireDiscordBot/k3s-infra.git
cd k3s-infra
TARGET_ENV=${{ steps.env-check.outputs.target }}
sed -i "s|image: ghcr.io/firediscordbot/bot:.*|image: ghcr.io/firediscordbot/bot:${{ github.sha }}|g" clusters/$TARGET_ENV/fire/fire.yaml
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "deploy($TARGET_ENV): update bot to ${{ github.sha }}"
git push