-
Notifications
You must be signed in to change notification settings - Fork 7
141 lines (137 loc) · 5.09 KB
/
docker-build-and-test.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Build and Test Docker
on:
workflow_call:
inputs:
platform:
type: string
required: true
jobs:
build:
name: 'Build: ${{ matrix.target }}'
runs-on: ubuntu-24.04
strategy:
matrix:
target: [ web, worker, legacy-importer, database-migration, e2e ]
continue-on-error: ${{ matrix.target == 'web' && inputs.platform == 'arm64' && github.event_name != 'push' }}
steps:
# https://github.com/actions/virtual-environments/issues/1187
- name: Tune linux network
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate image name
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}/${{ matrix.target }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
echo "IMAGE_ID=$IMAGE_ID" >> "$GITHUB_ENV"
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_ID }}
bake-target: ${{ matrix.target }}
- name: Build the Docker image
id: build
uses: docker/[email protected]
with:
files: |
./docker-compose.yml
./docker-compose.importer.yml
./docker-compose.e2e.yml
${{ steps.meta.outputs.bake-file-labels }}
targets: ${{ matrix.target }}
set: |
${{ matrix.target }}.output=type=image,push-by-digest=true,name-canonical=true,push=true
${{ matrix.target }}.tags=${{ env.IMAGE_ID }}
*.platform=linux/${{ inputs.platform }}
*.cache-from=type=gha,scope=build-${{ inputs.platform }}-${{ matrix.target }}
*.cache-to=type=gha,scope=build-${{ inputs.platform }}-${{ matrix.target }},mode=max
- name: Export digest
run: |
mkdir -p /tmp/digests/${{ matrix.target }}
digest=$(jq -cr '."${{ matrix.target }}"."containerimage.digest"' <<< '${{ steps.build.outputs.metadata }}')
touch "/tmp/digests/${{ matrix.target }}/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: docker-digests-${{ inputs.platform }}-${{ matrix.target }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
test-compose:
name: 'Test: docker compose'
runs-on: ubuntu-24.04
if: inputs.platform == 'amd64'
needs: build
steps:
- name: Add hosts
run: sudo echo "127.0.0.1 en.gw2treasures.localhost" | sudo tee -a /etc/hosts
- uses: actions/checkout@v4
- uses: ./.github/actions/pull-images
with:
platform: ${{ inputs.platform }}
- name: Start docker compose
run: docker compose up -d
- name: Wait 30s
run: sleep 30
- run: docker compose ps -a
- run: docker compose logs
- name: Verify docker containers are running
run: docker inspect --format "{{.ID}} {{.Name}} {{.State.Status}} {{.RestartCount}}" $(docker compose ps -aq) | node .github/actions/docker-compose-status.js
- run: curl --fail-with-body http://en.gw2treasures.localhost:3000/
- name: Stop docker compose
run: docker compose down
test-kubernetes:
name: 'Test: kubernetes'
runs-on: ubuntu-24.04
if: inputs.platform == 'amd64'
needs: build
steps:
- uses: actions/checkout@v4
- uses: nolar/setup-k3d-k3s@v1
with:
version: v1.26
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: ./.github/actions/pull-images
with:
platform: ${{ inputs.platform }}
- name: Import images into k3d
run: k3d image import gw2treasures/web gw2treasures/worker gw2treasures/legacy-importer gw2treasures/database-migration
- run: kubectl apply -k kubernetes/local
- run: kubectl rollout status deployment database-pg17 next worker -n gw2treasures --timeout=180s
- run: kubectl get deployment -n gw2treasures
if: success() || failure()
- run: kubectl get job -n gw2treasures
if: success() || failure()
- run: kubectl logs -l app.kubernetes.io/part-of=gw2treasures -n gw2treasures --all-containers --ignore-errors
if: failure() || runner.debug == '1'
test-e2e:
name: 'Test: e2e'
runs-on: ubuntu-24.04
if: inputs.platform == 'amd64'
needs: build
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/pull-images
with:
platform: ${{ inputs.platform }}
- name: Start docker compose
run: docker compose -f docker-compose.yml -f docker-compose.e2e.yml up -d web database database-migration
- name: Wait for containers to be up
run: sleep 30
- name: Run e2e tests
run: docker compose -f docker-compose.yml -f docker-compose.e2e.yml up e2e --no-log-prefix --exit-code-from e2e
- name: Stop docker compose
run: docker compose down