name: Build a new image for the MycroForge docs run-name: ${{ gitea.actor }} triggered a build for the MycroForge docs image on: [ push ] jobs: build: runs-on: ubuntu-latest if: gitea.ref == 'refs/heads/main' steps: - uses: https://github.com/actions/checkout@v4 - 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 echo ${{ secrets.DOCKER_PASS }} | docker login git.devdisciples.com --username ${{ secrets.DOCKER_USER }} --password-stdin # 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