Skip to content

Commit

Permalink
Add GH action that builds node docker image
Browse files Browse the repository at this point in the history
This is copied from https://github.com/danskernesdigitalebibliotek/dpl-cms
and altered to be node specific.
  • Loading branch information
spaceo committed Sep 27, 2024
1 parent 518ecc9 commit a3bfd19
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/publish-source.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow takes care of building and publishing the source code of the Danish Public Libraries CMS.
name: Publish source
on: create
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Validate the format of the tag. We only want to react on a precise pattern.
- name: Detect release tag
id: detect_tag
run: |
if [[ "${{ github.ref }}" =~ ^refs/tags/[0-9]+\.[0-9]+\.[0-9]+$ ]]
then
echo ::set-output name=IS_RELEASE_TAG::true
else
echo ::set-output name=IS_RELEASE_TAG::false
fi
# Extract version from tag.
- name: Get version
id: get_version
run: |
echo ::set-output name=RELEASE_TAG::$(echo ${GITHUB_REF#refs/tags/} | cut -d '_' -f 2)
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
# Write version to .version file.
- name: Create .version file
run: |
echo "{\"version\": \"${{ steps.get_version.outputs.RELEASE_TAG }}\"}" > .version
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
# Install go-task since we need it for building the source package.
- name: Install go-task
uses: arduino/setup-task@v2
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
- name: Build and publish source
run: |
echo "Publishing tag: $RELEASE_TAG"
RELEASE_IMAGE_TAG=$RELEASE_TAG RELEASE_IMAGE_REGISTRY=ghcr.io/${{ github.repository_owner}} task source:deploy
if: ${{ steps.detect_tag.outputs.IS_RELEASE_TAG == 'true' }}
env:
CR_PAT: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ steps.get_version.outputs.RELEASE_TAG }}
52 changes: 52 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This is a go-task file for various developer tasks
# e.g. building docker images and setting up local development.
# You can read about the Task files here: https://taskfile.dev.
version: "3"

dotenv: [".task.env"]

vars:
# Docker image registry.
# Eg.
# - ghcr.io/danskernesdigitalebibliotek
# - docker.io/someregistry
RELEASE_IMAGE_REGISTRY: '{{.RELEASE_IMAGE_REGISTRY | default "ghcr.io/danskernesdigitalebibliotek"}}'
# Get total amount of commits on the main branch. Used as build number.
COMMIT_COUNT:
sh: git rev-list --count origin/main
# The version number we want to tag the source build with.
# It can be specified by adding RELEASE_TAG=XX when running command.
# Otherwise it will default to the COMMIT_COUNT variable.
RELEASE_IMAGE_TAG: "{{.RELEASE_IMAGE_TAG | default .COMMIT_COUNT }}"
# Constructing docker image name.
RELEASE_IMAGE_NAME: '{{.RELEASE_IMAGE_NAME | default "dpl-go-node"}}'
RELEASE_FULL_NAME: "{{.RELEASE_IMAGE_REGISTRY}}/{{.RELEASE_IMAGE_NAME}}:{{.RELEASE_IMAGE_TAG}}"
# Where is the docker file(s) we use for our builds residing?
LAGOON_DIR: "lagoon"


tasks:
ghcr:login:
summary: Login into Github Container Registry
cmds:
- echo {{ .CR_PAT }} | docker login {{ .RELEASE_IMAGE_REGISTRY }} -u username-not-used --password-stdin
preconditions:
- sh: "[ ! -z {{.CR_PAT}} ]"
msg: "Env variable CR_PAT is not set or empty."

source:build:
summary: Build node image.
cmds:
- docker build -f {{ .LAGOON_DIR }}/node.dockerfile --tag {{ .RELEASE_FULL_NAME }} .

source:push:
summary: Push core source image to container registry.
deps: [ghcr:login]
cmds:
- docker push {{ .RELEASE_FULL_NAME }}

source:deploy:
desc: Build and push core source docker image.
cmds:
- task: source:build
- task: source:push
16 changes: 16 additions & 0 deletions lagoon/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Dockerfiles

This directory contains the Dockerfiles that are used during the deployment
of branch and PR environments for DPL CMS and for building source releases.

the cli, nginx and php dockerfiles are used to generate the container-images
that Lagoon uses in PR/Branch environments. These files mirrors the files used
for production deployments in
<https://github.com/danskernesdigitalebibliotek/dpl-platform/blob/main/infrastructure/dpladm/env-repo-template/>
. Should you need to make modifications to these files, make sure to also make
the changes to the production versions.

`source.dockerfile` is used build and store a release of dpl-cms. For PR/branch
environments the file is used as the first step in building the Lagoon images.
The same file is used by the Github action that builds tagged releases of
dpl-cms.
11 changes: 11 additions & 0 deletions lagoon/node.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM uselagoon/node-20-builder:latest as builder
COPY package.json /app/
RUN yarn install

FROM uselagoon/node-20:latest
COPY --from=builder /app/node_modules /app/node_modules
COPY . /app/

EXPOSE 3000

CMD ["/app/lagoon/start.sh"]
14 changes: 14 additions & 0 deletions lagoon/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# if [ $LAGOON_ENVIRONMENT_TYPE == "production" ]; then
# cd /app
# npm run start
# else
# cd /app
# npm run dev
# fi

cd /app
npm run start

exit 0;

0 comments on commit a3bfd19

Please sign in to comment.