Skip to content

Commit a080aa7

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 a080aa7

File tree

3 files changed

+103
-0
lines changed

3 files changed

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

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
RUN chmod +x ./dist/src/cli.js
15+
ENTRYPOINT ["./dist/src/cli.js"]

0 commit comments

Comments
 (0)