Skip to content

Commit feb9cfb

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 feb9cfb

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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: Checkout repository
26+
uses: actions/[email protected]
27+
with: { fetch-depth: 0 }
28+
- name: Log in to GitHub Container Repository
29+
run: docker login "$SERVER" --username "$USER" --password "$PASSWORD"
30+
- name: Get image tags
31+
id: vars
32+
run: |
33+
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
34+
FULL_TAG="${GITHUB_REF#refs/tags/}" # Remove refs/tags/
35+
echo "full_tag=$FULL_TAG" >> $GITHUB_OUTPUT
36+
# Remove leading 'v' if present
37+
VERSION="${FULL_TAG#v}"
38+
# Remove pre-release or build metadata (anything after '-')
39+
VERSION="${VERSION%%-*}"
40+
# Split version like "1.2.3" into "1.2.3", "1.2", "1"
41+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
42+
echo "tags=$FULL_TAG,$MAJOR.$MINOR,$MAJOR" >> $GITHUB_OUTPUT
43+
else
44+
echo "full_tag=latest" >> $GITHUB_OUTPUT
45+
echo "tags=latest" >> $GITHUB_OUTPUT
46+
fi
47+
- name: Build docker image
48+
run: |
49+
tag="$SERVER/$USER/$REPO:${{ steps.vars.outputs.full_tag }}"
50+
docker build --target "$TARGET" --tag "$tag" .
51+
- name: Basic container runtime test
52+
run: docker run --rm "$SERVER/$USER/$REPO:${{ steps.vars.outputs.full_tag }}" --help
53+
- name: Tag docker image with multiple tags
54+
run: |
55+
for tag in $(echo "${{ steps.vars.outputs.tags }}" | tr ',' ' '); do
56+
image="$SERVER/$USER/$REPO:${{ steps.vars.outputs.full_tag }}"
57+
alias="$SERVER/$USER/$REPO:$tag"
58+
docker tag "$image" "$alias"
59+
done
60+
- name: Push created image to registry
61+
run: |
62+
for tag in $(echo "${{ steps.vars.outputs.tags }}" | tr ',' ' '); do
63+
docker push "$SERVER/$USER/$REPO:$tag"
64+
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 ls -l
7+
RUN npm run test
8+
RUN npm run build
9+
10+
FROM node:24-alpine AS production
11+
WORKDIR /app
12+
COPY package.json package-lock.json ./
13+
RUN npm ci --omit=dev
14+
COPY --from=build /build/dist ./dist
15+
CMD [ "npm", "--silent", "run", "start", "--"]

0 commit comments

Comments
 (0)