From c551a3ee45dceed890ec6a9a3ff79c5da6c8b8c8 Mon Sep 17 00:00:00 2001 From: Marco La Rosa Date: Fri, 3 Nov 2023 12:16:00 +1100 Subject: [PATCH] setup container builds for application --- .github/workflows/release.yml | 33 +++++++++++++++++++++++++++++++++ Dockerfile | 11 +++++++++++ build-container.sh | 9 +++++++++ version-and-push.sh | 19 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile create mode 100755 build-container.sh create mode 100755 version-and-push.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e7f3a15 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Build packages and publish to Github Container Registry + +on: + push: + tags: + - '*' + +env: + REGISTRY: ghcr.io + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v3 + + - name: Install Node.js, NPM and Yarn + uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Log in to the Container registry + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build the containers + run: ./build-container.sh ${{ github.ref_name }} + shell: bash \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f102da3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:latest +LABEL org.opencontainers.image.source=https://github.com/CoEDL/50words.online +LABEL org.opencontainers.image.description="The 50 words application" +LABEL org.opencontainers.image.licenses=GPLv3 + +# RUN apt-get update && apt-get install -y nginx-extras +RUN rm /etc/nginx/conf.d/default.conf + +COPY ./dist/ /srv/50words/www/ + +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/build-container.sh b/build-container.sh new file mode 100755 index 0000000..198cbd1 --- /dev/null +++ b/build-container.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +VERSION=$1 +echo "Building $VERSION" + +# build the 50words application container +npm run build:production +docker build --push --rm \ + -t ghcr.io/coedl/50words.online:latest . diff --git a/version-and-push.sh b/version-and-push.sh new file mode 100755 index 0000000..d7f8678 --- /dev/null +++ b/version-and-push.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +if [ "$#" != "1" ] ; then + echo "Usage: $0 [minor | patch]" + exit -1 +fi + +if [[ $1 != 'minor' && $1 != 'patch' ]] ; then + echo "Usage: $0 [minor | patch]" + exit -1 +fi + +# version the code +version=$(npm version --no-git-tag-version $1) +git tag $version +git commit -a -m "tag and bump version" + +# push it to github to trigger container builds +git push origin master --tags \ No newline at end of file