From fd04ffbc195cef8fab18b07c2a466d99479df595 Mon Sep 17 00:00:00 2001 From: mdnapo Date: Sun, 13 Oct 2024 14:25:25 +0200 Subject: [PATCH] Added build pipeline --- .gitea/workflows/build.yml | 37 +++++++++++++++++++++++++++++++++++++ package.json | 3 ++- test.sh | 12 ++++++++++++ version.txt | 1 + 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build.yml create mode 100755 test.sh create mode 100644 version.txt diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..5076c8e --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build a new image for the MycroForge docs +run-name: ${{ gitea.actor }} triggered a build for the MycroForge docs +on: [ push ] + +jobs: + test: + runs-on: ubuntu-latest + if: gitea.ref == 'refs/heads/main' + steps: + - uses: https://github.com/actions/checkout@v4 + - uses: https://github.com/actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + - name: "Build and push Docker image" + run: | + IMAGE_NAME="git.devdisciples.com/devdisciples/m4gdocs" + IMAGE_VERSION="$(cat version.txt)" + VERSIONED_IMAGE_TAG="$IMAGE_NAME:$IMAGE_VERSION" + LATEST_IMAGE_TAG="$IMAGE_NAME:latest" + + # Login to the registry + docker login git.devdisciples.com --username ${{ DOCKER_USER }} --password-stdin ${{ DOCKER_PASS }} + + # Check if the image exists. + # EXISTS = 0 if the image was found else 1. + EXISTS=$(docker manifest inspect $VERSIONED_TAG > /dev/null 2>&1; echo $?) + + # Build a new image and push it if the versioned tag was not found. + if [[ $EXISTS -eq 1 ]]; then + docker build -t $VERSIONED_IMAGE_TAG -t $LATEST_IMAGE_TAG . + docker push $VERSIONED_IMAGE_TAG + docker push $LATEST_IMAGE_TAG + # Else notify the user that the image tag already exists and exit with status code 1. + else + echo "Image $VERSIONED_TAG already exists, you should probably increment the version." + exit 1 + fi diff --git a/package.json b/package.json index 4a962d1..8a1e11f 100644 --- a/package.json +++ b/package.json @@ -43,5 +43,6 @@ }, "engines": { "node": ">=18.0" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..9e6abad --- /dev/null +++ b/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + + +EXISTS=$(docker manifest inspect git.devdisciples.com/devdisciples/m4gdocs:latests > /dev/null 2>&1; echo $?) + +echo $EXISTS + +if [[ $EXISTS -eq 1 ]]; then + echo "Image does not exist." +else + echo "Image exists." +fi \ No newline at end of file diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file