|
| 1 | +name: iroha2-all-in-one-publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Publish `main` as Docker `latest` image. |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | + # Publish `v1.2.3` tags as releases. |
| 10 | + tags: |
| 11 | + - v* |
| 12 | + |
| 13 | +env: |
| 14 | + IMAGE_NAME: cactus-iroha2-all-in-one |
| 15 | + |
| 16 | +jobs: |
| 17 | + # Push image to GitHub Packages. |
| 18 | + # See also https://docs.docker.com/docker-hub/builds/ |
| 19 | + build-tag-push-container: |
| 20 | + runs-on: ubuntu-20.04 |
| 21 | + env: |
| 22 | + DOCKER_BUILDKIT: 1 |
| 23 | + DOCKERFILE_PATH: ./tools/docker/iroha2-all-in-one/Dockerfile |
| 24 | + DOCKER_BUILD_DIR: ./tools/docker/iroha2-all-in-one/ |
| 25 | + permissions: |
| 26 | + packages: write |
| 27 | + contents: read |
| 28 | + |
| 29 | + steps: |
| 30 | + |
| 31 | + |
| 32 | + - name: Build image |
| 33 | + run: docker build $DOCKER_BUILD_DIR --file $DOCKERFILE_PATH --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" |
| 34 | + |
| 35 | + - name: Log in to registry |
| 36 | + # This is where you will update the PAT to GITHUB_TOKEN |
| 37 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 38 | + |
| 39 | + - name: Push image |
| 40 | + run: | |
| 41 | + SHORTHASH=$(git rev-parse --short "$GITHUB_SHA") |
| 42 | + TODAYS_DATE="$(date +%F)" |
| 43 | + DOCKER_TAG="$TODAYS_DATE-$SHORTHASH" |
| 44 | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME |
| 45 | + # Change all uppercase to lowercase |
| 46 | + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') |
| 47 | + # Strip git ref prefix from version |
| 48 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 49 | + # Strip "v" prefix from tag name |
| 50 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 51 | + # Do not use the `latest` tag at all, tag with date + git short hash if there is no git tag |
| 52 | + [ "$VERSION" == "main" ] && VERSION=$DOCKER_TAG |
| 53 | + echo IMAGE_ID=$IMAGE_ID |
| 54 | + echo VERSION=$VERSION |
| 55 | + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION |
| 56 | + docker push $IMAGE_ID:$VERSION |
0 commit comments