Skip to content

Commit 458282c

Browse files
committed
Build and push Docker image after full CI workflow
1 parent f22e691 commit 458282c

4 files changed

Lines changed: 146 additions & 52 deletions

File tree

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
VITE_MAPTILER_API_KEY: '${{ secrets.MAPTILER_API_KEY }}'
11+
IMAGE_PROJECT: dft-rlg-atip-dev
12+
IMAGE_LOCATION: europe-west1
13+
IMAGE_REPOSITORY_ID: docker
14+
IMAGE_NAME: plan
15+
16+
jobs:
17+
check:
18+
timeout-minutes: 60
19+
runs-on: ubuntu-22.04
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- uses: actions/setup-node@v3
24+
with:
25+
node-version: 22.x
26+
cache: 'npm'
27+
28+
- name: Install wasm-pack
29+
uses: jetli/wasm-pack-action@v0.4.0
30+
31+
- name: Install dependencies
32+
run: npm ci
33+
34+
- name: Setup GOV.UK
35+
run: npm run setup-govuk
36+
37+
- name: Install Playwright Browsers
38+
run: npx playwright install --with-deps
39+
40+
- name: Run type-checker
41+
run: npm run check
42+
43+
- name: Run Playwright tests
44+
run: npm test
45+
46+
- name: Upload test results
47+
run: npx github-actions-ctrf ctrf/ctrf-report.json
48+
if: always()
49+
50+
- name: Upload test results for historical report
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: ctrf-report
54+
path: ctrf/ctrf-report.json
55+
if: always()
56+
57+
- name: Build svelte app
58+
run: npm run build
59+
60+
- id: auth
61+
name: Authenticate with Google Cloud
62+
uses: google-github-actions/auth@v3
63+
with:
64+
token_format: access_token
65+
credentials_json: '${{ secrets.GCP_CREDENTIALS_PUSH }}'
66+
67+
- name: Login to Docker repository
68+
uses: docker/login-action@v4
69+
with:
70+
registry: ${{ env.IMAGE_LOCATION }}-docker.pkg.dev
71+
username: oauth2accesstoken
72+
password: ${{ steps.auth.outputs.access_token }}
73+
74+
- id: meta
75+
name: Extract metadata
76+
uses: docker/metadata-action@v6
77+
with:
78+
images: ${{ env.IMAGE_LOCATION }}-docker.pkg.dev/${{ env.IMAGE_PROJECT }}/${{ env.IMAGE_REPOSITORY_ID }}/${{ env.IMAGE_NAME }}
79+
tags: |
80+
type=semver,pattern={{version}}
81+
type=ref,event=branch,enable={{is_not_default_branch}}
82+
type=raw,value=latest,enable={{is_default_branch}}
83+
84+
- name: Build and push image
85+
uses: docker/build-push-action@v7
86+
with:
87+
context: .
88+
tags: ${{ steps.meta.outputs.tags }}
89+
labels: ${{ steps.meta.outputs.labels }}
90+
push: true

.github/workflows/playwright.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM node:22-slim
2+
3+
ENV PORT=8080
4+
5+
WORKDIR /usr/src/app
6+
COPY backend .
7+
8+
RUN npm install --production
9+
10+
USER node
11+
12+
CMD [ "sh", "-c", "npm start" ]

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,50 @@ You can also configure the application locally by setting the following environm
8686

8787
1. Open http://localhost:8080
8888

89+
## Running locally using Docker
90+
91+
To run the server as a container:
92+
93+
1. Build the svelte app
94+
95+
```bash
96+
npm install && npm run build
97+
```
98+
99+
2. Copy over the built svelte app
100+
101+
```bash
102+
cp -r dist backend/
103+
```
104+
105+
1. Build the Docker image
106+
107+
```bash
108+
docker build -t plan .
109+
```
110+
111+
1. Authenticate with Google
112+
113+
```bash
114+
gcloud auth application-default login
115+
```
116+
117+
1. Run the Docker image
118+
119+
```bash
120+
ADC=~/.config/gcloud/application_default_credentials.json
121+
122+
docker run --rm -it \
123+
-e GCS_BUCKET=dft-rlg-atip-dev \
124+
-e USE_IAP=false \
125+
-e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/google_credentials.json \
126+
-v ${ADC}:/tmp/keys/google_credentials.json:ro \
127+
-p 8080:8080 \
128+
plan
129+
```
130+
131+
1. Open http://127.0.0.1:8080
132+
89133

90134
### Developing with Vite
91135

0 commit comments

Comments
 (0)