Skip to content

Commit 7868609

Browse files
chore: added ci workflow to build and push image
This workflow will push new images on changes to significant branches. This allows users to pull slyde as a docker image.
1 parent 7411b72 commit 7868609

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
dist
3+
ignore
4+
docs
5+
coverage
6+
.github
7+
.git*
8+
.cache
9+
.tsbuildinfo
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build container image
2+
# On pushes to the main branches, build and push the newly created docker
3+
# images to the GitHub Container Repository where people can pull them from.
4+
5+
on:
6+
push:
7+
branches: [main, master, release, development]
8+
tags: [v*.*.*]
9+
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
jobs:
15+
build:
16+
name: build and push container image
17+
runs-on: ubuntu-latest
18+
env:
19+
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
20+
REPO: ${{ github.event.repository.name }}
21+
USER: ${{ github.actor }}
22+
TARGET: production
23+
SERVER: ghcr.io
24+
steps:
25+
- name: Make lower case image environment variable
26+
run: |
27+
# images need to be lower case
28+
full="$SERVER/$USER/$REPO"
29+
echo "IMAGE=${full,,}" >> $GITHUB_ENV
30+
- name: Checkout repository
31+
uses: actions/checkout@v6.0.1
32+
with: { fetch-depth: 0 }
33+
- name: Log in to GitHub Container Repository
34+
run: docker login "$SERVER" --username "$USER" --password "$PASSWORD"
35+
- name: Get image tags
36+
id: vars
37+
run: |
38+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
39+
FULL_TAG="${GITHUB_REF#refs/tags/}" # Remove refs/tags/
40+
echo "full_tag=$FULL_TAG" >> $GITHUB_OUTPUT
41+
# Remove leading 'v' if present
42+
VERSION="${FULL_TAG#v}"
43+
# Remove pre-release or build metadata (anything after '-')
44+
VERSION="${VERSION%%-*}"
45+
# Split version like "1.2.3" into "1.2.3", "1.2", "1"
46+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
47+
echo "tags=$FULL_TAG,$MAJOR.$MINOR,$MAJOR" >> $GITHUB_OUTPUT
48+
else
49+
echo "full_tag=latest" >> $GITHUB_OUTPUT
50+
echo "tags=latest" >> $GITHUB_OUTPUT
51+
fi
52+
- name: Build docker image
53+
run: |
54+
tag="$IMAGE:${{ steps.vars.outputs.full_tag }}"
55+
docker build --target "$TARGET" --tag "$tag" .
56+
- name: Basic container runtime test
57+
run: docker run --rm "$IMAGE:${{ steps.vars.outputs.full_tag }}" --help
58+
- name: Tag docker image with multiple tags
59+
run: |
60+
for tag in $(echo "${{ steps.vars.outputs.tags }}" | tr ',' ' '); do
61+
image="$IMAGE:${{ steps.vars.outputs.full_tag }}"
62+
alias="$IMAGE:$tag"
63+
docker tag "$image" "$alias"
64+
done
65+
- name: Push created image to registry
66+
run: |
67+
for tag in $(echo "${{ steps.vars.outputs.tags }}" | tr ',' ' '); do
68+
docker push "$IMAGE:$tag"
69+
done

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM node:24 AS build
2+
WORKDIR /build
3+
COPY package.json package-lock.json ./
4+
RUN npm ci
5+
COPY ./ ./
6+
RUN npm run test
7+
RUN npm run build
8+
9+
FROM node:24-alpine AS production
10+
WORKDIR /app
11+
COPY package.json package-lock.json ./
12+
RUN npm ci --omit=dev
13+
COPY --from=build /build/dist ./dist
14+
CMD [ "npm", "--silent", "run", "start", "--"]

0 commit comments

Comments
 (0)