Added build pipeline
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 26s

This commit is contained in:
mdnapo 2024-10-13 14:25:25 +02:00
parent 0747a730ee
commit fd04ffbc19
4 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -43,5 +43,6 @@
},
"engines": {
"node": ">=18.0"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

12
test.sh Executable file
View File

@ -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

1
version.txt Normal file
View File

@ -0,0 +1 @@
0.0.1