Repository navigation
181 lines (155 loc) · 5.69 KB
/
Copy pathdocker.yml
File metadata and controls
181 lines (155 loc) · 5.69 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: Docker CI
on:
push:
branches:
- main
- dev
tags:
- "v*"
- "beta-*"
pull_request:
branches:
- main
- dev
workflow_dispatch:
env:
PROXY_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/shadowschema
DASHBOARD_IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/shadowschema-dashboard
permissions:
contents: read
packages: write
jobs:
test:
name: Test Docker images
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build proxy image
run: docker build -t shadowschema-smoke .
- name: Build dashboard image
run: docker build -f Dockerfile.dashboard -t shadowschema-dashboard-smoke .
- name: Smoke test proxy container
run: |
docker network create shadowschema-smoke-net
docker run -d \
--name shadowschema-postgres-smoke \
--network shadowschema-smoke-net \
-e POSTGRES_USER=shadowschema \
-e POSTGRES_PASSWORD=shadowschema \
-e POSTGRES_DB=shadowschema \
postgres:16-alpine
for attempt in $(seq 1 30); do
if docker exec shadowschema-postgres-smoke pg_isready -U shadowschema -d shadowschema >/dev/null 2>&1; then
break
fi
if [ "$attempt" = "30" ]; then
docker logs shadowschema-postgres-smoke
exit 1
fi
sleep 1
done
docker run -d \
--name shadowschema-smoke \
--network shadowschema-smoke-net \
-e DATABASE_URL=postgres://shadowschema:shadowschema@shadowschema-postgres-smoke:5432/shadowschema?sslmode=disable \
-p 38080:38080 \
-p 38081:38081 \
shadowschema-smoke
for attempt in $(seq 1 30); do
if curl -fsS http://localhost:38081/export-map >/dev/null; then
break
fi
if [ "$attempt" = "30" ]; then
docker logs shadowschema-smoke
exit 1
fi
sleep 1
done
curl -fsS http://localhost:38081/export-map | grep -q '"openapi"'
- name: Stop proxy smoke container
if: always()
run: |
docker rm -f shadowschema-smoke 2>/dev/null || true
docker rm -f shadowschema-postgres-smoke 2>/dev/null || true
docker network rm shadowschema-smoke-net 2>/dev/null || true
- name: Smoke test dashboard container
run: |
docker run -d --name shadowschema-dashboard-smoke -p 8080:8080 shadowschema-dashboard-smoke
for attempt in $(seq 1 20); do
if curl -fsS http://localhost:8080/ >/dev/null; then
break
fi
if [ "$attempt" = "20" ]; then
docker logs shadowschema-dashboard-smoke
exit 1
fi
sleep 1
done
- name: Stop dashboard smoke container
if: always()
run: docker rm -f shadowschema-dashboard-smoke 2>/dev/null || true
publish:
name: Publish Docker images
runs-on: ubuntu-latest
needs: test
if: github.event_name != 'pull_request'
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata (proxy)
id: proxy_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.PROXY_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
type=raw,value=beta,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha,prefix=main-,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=dev-,enable=${{ github.ref == 'refs/heads/dev' }}
type=ref,event=tag
- name: Build and publish proxy image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.proxy_meta.outputs.tags }}
labels: ${{ steps.proxy_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract Docker metadata (dashboard)
id: dashboard_meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DASHBOARD_IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
type=raw,value=beta,enable=${{ github.ref == 'refs/heads/dev' }}
type=sha,prefix=main-,enable=${{ github.ref == 'refs/heads/main' }}
type=sha,prefix=dev-,enable=${{ github.ref == 'refs/heads/dev' }}
type=ref,event=tag
- name: Build and publish dashboard image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.dashboard
push: true
tags: ${{ steps.dashboard_meta.outputs.tags }}
labels: ${{ steps.dashboard_meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max