Skip to content

Commit 08847e7

Browse files
committed
Test action for building docker image.
1 parent 8c93d13 commit 08847e7

File tree

5 files changed

+106
-75
lines changed

5 files changed

+106
-75
lines changed

.dockerignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Dockerfile
2+
.dockerignore
3+
.git
4+
.gitignore
5+
.gitattributes
6+
README.md
7+
.npmrc
8+
.prettierrc
9+
.eslintrc.cjs
10+
.graphqlrc
11+
.editorconfig
12+
.svelte-kit
13+
.vscode
14+
node_modules
15+
build
16+
package
17+
**/.env

.github/workflows/deploy.yml

+36-39
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,48 @@
1-
name: Build & Deploy
1+
#
2+
name: Create and publish a Docker image
23

34
on:
45
push:
5-
branches: [ "main" ]
6+
branches: ['main']
67

7-
pull_request:
8-
branches: [ "main" ]
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
911

1012
jobs:
11-
build-and-deploy:
12-
env:
13-
PUBLIC_GRAPHQL_API_URL: "https://api.vra.stevecrow.dev"
13+
build-and-push-image:
1414
runs-on: ubuntu-latest
15-
16-
strategy:
17-
matrix:
18-
node-version: [ 18.x ]
19-
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
2020
steps:
21-
- name: Check out repository
21+
- name: Checkout repository
2222
uses: actions/checkout@v4
23-
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v3
23+
- name: Log in to the Container registry
24+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
2625
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: "npm"
29-
30-
- run: npm ci
31-
- run: npm run build --if-present
32-
- run: npm run test --if-present
33-
34-
- uses: a7ul/[email protected]
26+
registry: ${{ env.REGISTRY }}
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
3532
with:
36-
command: c
37-
cwd: "./"
38-
files: |
39-
build/
40-
Dockerfile
41-
node_modules/
42-
package.json
43-
package-lock.json
44-
outPath: deploy.tar
45-
46-
- name: Deploy App to CapRover
47-
uses: caprover/[email protected]
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
- name: Build and push Docker image
35+
id: push
36+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
4837
with:
49-
server: '${{ secrets.CAPROVER_SERVER }}'
50-
app: '${{ secrets.CLIENT_APP_NAME }}'
51-
token: '${{ secrets.CLIENT_APP_TOKEN }}'
38+
context: .
39+
push: true
40+
tags: ${{ steps.meta.outputs.tags }}
41+
labels: ${{ steps.meta.outputs.labels }}
42+
- name: Generate artifact attestation
43+
uses: actions/attest-build-provenance@v2
44+
with:
45+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
46+
subject-digest: ${{ steps.push.outputs.digest }}
47+
push-to-registry: true
48+

Dockerfile

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
FROM node:18-alpine
1+
FROM node:22-alpine AS builder
2+
WORKDIR /app
3+
COPY package*.json ./
4+
RUN npm ci
5+
COPY . .
6+
RUN npm run build
7+
RUN npm prune --production
28

9+
FROM node:22-alpine
310
WORKDIR /app
11+
COPY --from=builder /app/build build/
12+
COPY --from=builder /app/node_modules node_modules/
413

14+
COPY package.json .
15+
EXPOSE 3000
516
ENV NODE_ENV=production
6-
ENV PORT=80
7-
8-
COPY package.json package-lock.json ./
9-
10-
RUN npm ci --omit dev
11-
12-
COPY build ./build
13-
14-
EXPOSE 80
15-
16-
CMD ["node", "build"]
17+
CMD [ "node", "build" ]

package-lock.json

+36-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)