From b8d5d1a1c936cead5f61d027c5bfa1566f2d0cf4 Mon Sep 17 00:00:00 2001 From: Amninder Kaur <36900343+akaur13@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:34:17 +1100 Subject: [PATCH] Feature/GitHub actions to publish lock manager image (#11) git workflow for creating pit-lock-manager image and pushing to ghcr.io --------- Co-authored-by: Amninder Kaur --- .github/workflows/build.yml | 7 ++++++ .github/workflows/ghcr_publish.yml | 40 ++++++++++++++++++++++++++++++ .github/workflows/npm_build.yml | 18 ++++++++++++++ bin/ghcr-publish.sh | 13 ++++++++++ bin/npm-build.sh | 12 +++++++++ bin/ubuntu-setup.sh | 4 +++ lock-manager/.env.example | 22 ++++++++++++++++ 7 files changed, 116 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ghcr_publish.yml create mode 100644 .github/workflows/npm_build.yml create mode 100644 bin/ghcr-publish.sh create mode 100644 bin/npm-build.sh create mode 100755 bin/ubuntu-setup.sh create mode 100644 lock-manager/.env.example diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b1f5540 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,7 @@ +name: build + +on: push + +jobs: + npm_build: + uses: ./.github/workflows/npm_build.yml diff --git a/.github/workflows/ghcr_publish.yml b/.github/workflows/ghcr_publish.yml new file mode 100644 index 0000000..e991728 --- /dev/null +++ b/.github/workflows/ghcr_publish.yml @@ -0,0 +1,40 @@ +name: ghcr.io Publish + +# when a new release is created or new tag is pushed to master +# tag should be in the format v1.0.0 +# v1.0.0-alpha.1 is also valid +# regex to check the tag format +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]' + - 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z]+' + - 'v[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z]+)+.[0-9]?' + +jobs: + build: + uses: ./.github/workflows/npm_build.yml + publish: + runs-on: ubuntu-latest + needs: build + if: needs.build.result == 'success' + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - run: PATH=$PATH:$(pwd) bin/ubuntu-setup.sh + - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - run: | + echo $RELEASE_VERSION + echo ${{ env.RELEASE_VERSION }} + - name: Build and publish lock manager image with ver and latest tag + run: sh bin/ghcr-publish.sh lock-manager $RELEASE_VERSION + + + + diff --git a/.github/workflows/npm_build.yml b/.github/workflows/npm_build.yml new file mode 100644 index 0000000..5a19dfb --- /dev/null +++ b/.github/workflows/npm_build.yml @@ -0,0 +1,18 @@ +# workflow_call to build the rust app +name: npm_build_and_test + +on: workflow_call + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 18 + check-latest: true + - name: npm install, build and test lock-manager + run: sh bin/npm-build.sh lock-manager diff --git a/bin/ghcr-publish.sh b/bin/ghcr-publish.sh new file mode 100644 index 0000000..d1a0826 --- /dev/null +++ b/bin/ghcr-publish.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e +package_name=$1 +version=$2 + +cd $package_name +tag_with_version=pit-$package_name:$version +tag_ref=ghcr.io/kindredgroup/pit-toolkit/$tag_with_version +echo $tag_ref +docker build . --tag $tag_ref +#for ghcr.io access token mentioned in the github secrets and accessed in actions +docker push $tag_ref diff --git a/bin/npm-build.sh b/bin/npm-build.sh new file mode 100644 index 0000000..74cce57 --- /dev/null +++ b/bin/npm-build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +package_name=$1 + +echo "Building $package_name" +cd $(pwd)/$package_name +npm ci +npm run build +npm run test +cd ../ diff --git a/bin/ubuntu-setup.sh b/bin/ubuntu-setup.sh new file mode 100755 index 0000000..1f49a91 --- /dev/null +++ b/bin/ubuntu-setup.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +sudo apt-get update && sudo apt-get install -y libsasl2-dev diff --git a/lock-manager/.env.example b/lock-manager/.env.example new file mode 100644 index 0000000..c17e26e --- /dev/null +++ b/lock-manager/.env.example @@ -0,0 +1,22 @@ +LOCAL_HOST_IP=$(ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}') + +K8S_NAMESPACE=dev +REGISTRY_URL=ksp +#IMAGE_TAG=$(git rev-parse --short HEAD) +IMAGE_TAG=dev + +SERVICE_NAME=lock-manager +SERVICE_PORT=60001 + +# POSTGRES +PGHOST=$LOCAL_HOST_IP +PGPORT= +PGUSER= +PGPASSWORD= +PGDATABASE= +PGMINPOOLSIZE=10 + +#DATABASE_URL=postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$PGDATABASE?sslmode=disable + +RENEW_BY_IN_SEC=60 +ENVIRONMENT=dev