-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (106 loc) · 3.75 KB
/
build.yaml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: "Build and push"
on:
push:
branches: [ main ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.23
cache: false
- uses: actions/checkout@v4
- name: go-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m0s
# Detect services that need to be built via the builder
detect-services:
runs-on: ubuntu-latest
outputs:
services: ${{ steps.detect-services.outputs.services }}
steps:
- uses: actions/setup-go@v4
with:
go-version: 1.23
cache: false
- uses: actions/checkout@v4
with:
fetch-depth: '0'
# Setup Go so we can run the builder
- name: detect-services
id: detect-services
run: |
services=$(go run builder/main.go)
echo "Raw services output: $services"
echo "services=$services" >> $GITHUB_OUTPUT
- name: print-services
run: |
echo "Services: ${{ steps.detect-services.outputs.services }}"
build-and-publish:
needs: [detect-services, lint]
if: needs.detect-services.outputs.services != '[]' # Only run if there are services to build
runs-on: ubuntu-latest
strategy:
matrix:
service: ${{ fromJson(needs.detect-services.outputs.services) }}
steps:
- uses: actions/checkout@v4
- name: "Identify Environment"
shell: bash
run: |
tag_prefix="ghcr.io/emortalmc/${{ matrix.service }}"
tags=""
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
tags="$tag_prefix:${{ github.sha }},$tag_prefix:latest"
else
tags="$tag_prefix:${{ github.sha }}"
fi
echo "DOCKER_TAGS=$tags" >> "$GITHUB_ENV"
- name: "Login to container registry"
uses: "docker/login-action@v2"
with:
registry: "ghcr.io"
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"
- name: "Set up Docker Buildx"
uses: "docker/setup-buildx-action@v2"
- name: "Build and push"
uses: "docker/build-push-action@v4"
with:
context: "./services/${{ matrix.service }}"
file: "./services/${{ matrix.service }}/Dockerfile"
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.DOCKER_TAGS }}
deploy:
needs: [build-and-publish, detect-services]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Only run on main branch
env:
SERVICES: ${{ needs.detect-services.outputs.services }}
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
repository: "emortalmc/argocd-deployments"
ref: "main"
token: "${{ secrets.DEPLOYMENTS_REPO_TOKEN }}"
- name: "Update image version"
shell: "bash"
# git commit -a automatically adds files that have been modified
run: |
echo "Services: $SERVICES"
services_array=($(echo $SERVICES | jq -r '.[]'))
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
for service in "${services_array[@]}"; do
echo "Updating image for $service to ${{ github.sha }}"
sed -i "s|version: .*|version: ${{ github.sha }}|g" "service/values/$service.yaml"
git commit -a -m "Update $service to ${{ github.sha }}"
done
git push https://😛:[email protected]/emortalmc/argocd-deployments.git
env:
PUSH_TOKEN: "${{ secrets.DEPLOYMENTS_REPO_TOKEN }}"