Skip to content

Commit 85bc566

Browse files
committed
Add dockerfile and dockerfile creation step
1 parent b8cd3f8 commit 85bc566

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
dist
3+
node_modules
4+
.git
5+
.DS_Store
6+
.env

.github/workflows/docker-build.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- feat/*
8+
tags:
9+
- "v*"
10+
pull_request:
11+
branches:
12+
- main
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
IMAGE_NAME: ${{ github.repository }}
17+
18+
jobs:
19+
build-and-push:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
security-events: write
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up QEMU
31+
uses: docker/setup-qemu-action@v3
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Log in to Container Registry
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=ref,event=branch
50+
type=ref,event=pr
51+
type=semver,pattern={{version}}
52+
type=semver,pattern={{major}}.{{minor}}
53+
type=semver,pattern={{major}}
54+
type=raw,value=latest,enable={{is_default_branch}}
55+
56+
- name: Build and push Docker image
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
platforms: linux/amd64,linux/arm64
61+
push: true
62+
tags: ${{ steps.meta.outputs.tags }}
63+
labels: ${{ steps.meta.outputs.labels }}
64+
cache-from: type=gha
65+
cache-to: type=gha,mode=max
66+
provenance: true
67+
sbom: true
68+
69+
- name: Run Trivy vulnerability scanner
70+
uses: aquasecurity/trivy-action@master
71+
with:
72+
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
73+
format: "sarif"
74+
output: "trivy-results.sarif"
75+
76+
- name: Upload Trivy scan results to GitHub Security tab
77+
uses: github/codeql-action/upload-sarif@v3
78+
if: always()
79+
with:
80+
sarif_file: "trivy-results.sarif"

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Build stage
2+
FROM docker.io/library/node:lts-alpine AS builder
3+
WORKDIR /app
4+
COPY package*.json ./
5+
RUN npm ci
6+
COPY . .
7+
RUN npm run build
8+
9+
# Production stage
10+
FROM docker.io/library/nginx:alpine
11+
12+
# Add metadata labels
13+
LABEL org.opencontainers.image.title="GitHub Compare"
14+
LABEL org.opencontainers.image.description="A simple web application to compare release notes between two GitHub releases"
15+
LABEL org.opencontainers.image.authors="Ingmar Delsink"
16+
LABEL org.opencontainers.image.licenses="MIT"
17+
LABEL org.opencontainers.image.source="https://github.com/idelsink/github-compare"
18+
LABEL org.opencontainers.image.documentation="https://github.com/idelsink/github-compare#readme"
19+
20+
COPY --from=builder /app/dist /usr/share/nginx/html
21+
EXPOSE 80
22+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)