diff --git a/.github/workflows/prod-pipeline.yml b/.github/workflows/prod-pipeline.yml index 6981740cbd1..a343b96f293 100644 --- a/.github/workflows/prod-pipeline.yml +++ b/.github/workflows/prod-pipeline.yml @@ -1,20 +1,29 @@ -name: Build otp2-prod from release +name: Build v2-prod from release on: - push: - branches: - - otp2-prod - pull_request: - branches: - - otp2-prod + release: + types: + - published jobs: - docker-push: - if: github.ref == 'refs/heads/otp2-prod' + v2-release: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - - name: Build docker image from otp2-prod and push it - run: ./.github/workflows/scripts/build_and_push_prod.sh + - name: Set time zone to Europe/Helsinki + uses: zcong1993/setup-timezone@master + with: + timezone: "Europe/Helsinki" + - name: Check Tag + id: check-tag + run: | + if [[ ${GITHUB_REF##*/} =~ ^202[0-9][0-1][0-9][0-3][0-9] ]]; then + echo ::set-output name=match::true + fi + - name: Push latest image as v2-prod + if: steps.check-tag.outputs.match == 'true' + run: ./.github/workflows/scripts/push_prod.sh env: DOCKER_USER: ${{ secrets.DOCKER_USER }} DOCKER_AUTH: ${{ secrets.DOCKER_AUTH }} + DOCKER_BASE_TAG: v2-prod + DOCKER_DEV_TAG: v2 diff --git a/.github/workflows/scripts/build_and_push_dev.sh b/.github/workflows/scripts/build_and_push_dev.sh index c8b3b31fdc0..7e6fbd27023 100755 --- a/.github/workflows/scripts/build_and_push_dev.sh +++ b/.github/workflows/scripts/build_and_push_dev.sh @@ -2,7 +2,7 @@ set -e DOCKER_IMAGE="hsldevcom/opentripplanner" -DOCKER_TAG="otp2" +DOCKER_TAG="v2" COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") diff --git a/.github/workflows/scripts/build_and_push_prod.sh b/.github/workflows/scripts/build_and_push_prod.sh deleted file mode 100755 index 060d35d556c..00000000000 --- a/.github/workflows/scripts/build_and_push_prod.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -e - -DOCKER_IMAGE="hsldevcom/opentripplanner" -DOCKER_TAG="otp2-prod" - -COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") - -DOCKER_TAG_LONG=$DOCKER_TAG-$(date +"%Y-%m-%dT%H.%M.%S")-$COMMIT_HASH -DOCKER_IMAGE_TAG=$DOCKER_IMAGE:$DOCKER_TAG -DOCKER_IMAGE_TAG_LONG=$DOCKER_IMAGE:$DOCKER_TAG_LONG - -# Build image -echo Building OTP -docker build --tag="$DOCKER_IMAGE:builder" -f Dockerfile.builder . -docker run --rm --entrypoint tar "$DOCKER_IMAGE:builder" -c target|tar x -C ./ -docker build --tag="$DOCKER_IMAGE_TAG_LONG" -f Dockerfile . - -docker login -u $DOCKER_USER -p $DOCKER_AUTH -echo "Pushing $DOCKER_TAG image" -docker push $DOCKER_IMAGE_TAG_LONG -docker tag $DOCKER_IMAGE_TAG_LONG $DOCKER_IMAGE_TAG -docker push $DOCKER_IMAGE_TAG - -echo Build completed diff --git a/.github/workflows/scripts/push_prod.sh b/.github/workflows/scripts/push_prod.sh new file mode 100755 index 00000000000..72840a143cd --- /dev/null +++ b/.github/workflows/scripts/push_prod.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e + +COMMIT_HASH=$(git rev-parse --short "$GITHUB_SHA") +ORG=hsldevcom + +function imagedeploy { + DOCKER_IMAGE=$ORG/$1 + DOCKER_TAG=${DOCKER_BASE_TAG:-prod} + DOCKER_DEV_TAG=${DOCKER_DEV_TAG:-latest} + + DOCKER_TAG_LONG=$DOCKER_TAG-$(date +"%Y-%m-%dT%H.%M.%S")-$COMMIT_HASH + DOCKER_IMAGE_TAG=$DOCKER_IMAGE:$DOCKER_TAG + DOCKER_IMAGE_TAG_LONG=$DOCKER_IMAGE:$DOCKER_TAG_LONG + DOCKER_IMAGE_DEV=$DOCKER_IMAGE:$DOCKER_DEV_TAG + + echo "processing prod release" + docker pull $DOCKER_IMAGE_DEV + docker tag $DOCKER_IMAGE_DEV $DOCKER_IMAGE_TAG + docker tag $DOCKER_IMAGE_DEV $DOCKER_IMAGE_TAG_LONG + docker push $DOCKER_IMAGE_TAG + docker push $DOCKER_IMAGE_TAG_LONG +} + +docker login -u $DOCKER_USER -p $DOCKER_AUTH + +imagedeploy "opentripplanner" + +echo Deploy complete