Skip to content

Commit 795bb7c

Browse files
authored
Merge pull request #1 from bedaberner/CI_docker_build
Create docker-publish.yml
2 parents 6d0b280 + 71fe715 commit 795bb7c

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ "main", "master" ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
with:
25+
submodules: true
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@v4
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
type=sha
48+
type=raw,value=latest,enable={{is_default_branch}}
49+
50+
- name: Build and push Docker image
51+
uses: docker/build-push-action@v4
52+
with:
53+
context: .
54+
push: ${{ github.event_name != 'pull_request' }}
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
FROM node:12
1+
FROM node:20
22

33
# Create app directory
44
WORKDIR /usr/src/app
55

6-
# Install app dependencies
7-
# A wildcard is used to ensure both package.json AND package-lock.json are copied
8-
# where available (npm@5+)
6+
# Install git (needed for submodules)
7+
RUN apt-get update && apt-get install -y git
8+
9+
# Copy package files first for better caching
910
COPY package*.json ./
1011

12+
# Install dependencies
1113
RUN npm install
1214

1315
# Bundle app source
1416
COPY . .
1517

18+
# Initialize and update git submodules
19+
RUN git init
20+
RUN git config --global url."https://github.com/".insteadOf [email protected]:
21+
RUN git submodule init
22+
RUN git submodule update
23+
24+
# Run the update-browserslist-db as suggested in the warning
25+
RUN npx update-browserslist-db@latest
26+
1627
EXPOSE 8080
17-
CMD [ "npm", "run", "dev" ]
28+
CMD [ "npm", "run", "dev" ]

0 commit comments

Comments
 (0)