Skip to content

Commit

Permalink
Setup release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Sep 10, 2024
1 parent 3d30d00 commit 48b18ea
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
changelog:
exclude:
labels:
- exclude from release notes
categories:
- title: Maintenance
labels:
- maintenance
- title: New Features
labels:
- new feature
- title: Improvements
labels:
- improvement
- title: Bug Fixes
labels:
- bug
- title: Other
labels:
- "*"
4 changes: 4 additions & 0 deletions .github/workflows/push-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ jobs:
tests:
name: Run tests
uses: ./.github/workflows/run-tests.yaml

release:
name: Publish image (next)
uses: ./.github/workflows/release.yaml
65 changes: 65 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release new version

on:
workflow_call:
inputs:
latest:
description:
Release as the latest version, tagging the images with the version number found in
package.json.
default: false
type: boolean

jobs:
tags:
name: Compose version tags
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Parse semver number from package.json
run: |
PACKAGE_VERSION=$(cat package.json | jq '.version' | tr -d '"')
echo "MAJOR=$(echo $PACKAGE_VERSION | cut -d "." -f 1)" >> $GITHUB_ENV
echo "MINOR=$(echo $PACKAGE_VERSION | cut -d "." -f 2)" >> $GITHUB_ENV
echo "PATCH=$(echo $PACKAGE_VERSION | cut -d "." -f 3)" >> $GITHUB_ENV
- name: Compose Docker tags
run: |
echo "MAJOR_V=kaiku:$MAJOR" >> $GITHUB_ENV
echo "MINOR_V=kaiku:$MAJOR.$MINOR" >> $GITHUB_ENV
echo "FULL_V=kaiku:$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV
- name: Compose tag list
run: echo "TAG_LIST=$MAJOR_V,$MINOR_V,$FULL_V,kaiku:latest" >> $GITHUB_ENV
- name: Select correct tags
id: tags
run:
echo SELECTED_TAGS=$(if [ ${{ inputs.latest }} = true ]; then echo $TAG_LIST; else echo
"kaiku:next"; fi) >> $GITHUB_OUTPUT
outputs:
tag-list: ${{ steps.tags.outputs.SELECTED_TAGS }}

publish:
name: Publish image
needs:
- tags
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Testing
run: echo ${{ needs.tags.outputs.tag-list }}
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build production image
uses: docker/build-push-action@v5
with:
context: app
tags: ${{ needs.tags.outputs.tag-list }}
23 changes: 23 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Production image.
FROM node:20.17 AS build

ENV NODE_ENV=production

# Build backend.
WORKDIR /usr/src/app
COPY server/package.json server/package-lock.json ./
RUN npm ci
COPY app .
RUN npm run build

# Final build stage to pick only actually needed files into the image.
FROM node:20.17-alpine

USER node

WORKDIR /app
COPY --from=build /usr/src/app/dist ./dist
COPY --from=build /usr/src/app/node_modules ./node_modules

# Run database migrations before booting server.
CMD node dist/main.js

0 comments on commit 48b18ea

Please sign in to comment.