|
| 1 | +name: Backup live container |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - live-* |
| 7 | + |
| 8 | +jobs: |
| 9 | + backup-live-container-job: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Get the live release tag |
| 14 | + id: get_tag |
| 15 | + run: echo ::set-output name=BRANCH_TAG::$(echo $GITHUB_REF | cut -d / -f 3) |
| 16 | + |
| 17 | + - name: Backup live release |
| 18 | + env: |
| 19 | + COMMIT_SHA: ${{ github.sha }} |
| 20 | + DOCKER_REGISTRY_URL: ntbscontainerregistry.azurecr.io |
| 21 | + DOCKER_REGISTRY_AZURE_NAME: ntbsContainerRegistry |
| 22 | + DOCKER_REPOSITORY: ntbs-service |
| 23 | + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 24 | + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} |
| 25 | + BACKUP_DOCKER_REGISTRY_URL: ntbsbackups.azurecr.io |
| 26 | + BACKUP_DOCKER_REPOSITORY: ntbs-backups |
| 27 | + BACKUP_DOCKER_USERNAME: ${{ secrets.BACKUP_DOCKER_USERNAME }} |
| 28 | + BACKUP_DOCKER_PASSWORD: ${{ secrets.BACKUP_DOCKER_PASSWORD }} |
| 29 | + BACKUP_IMAGE_TAG: ${{ steps.get_tag.outputs.BRANCH_TAG }} |
| 30 | + run: | |
| 31 | + image_tag=$(az acr repository show-tags -n $DOCKER_REGISTRY_AZURE_NAME --repository $DOCKER_REPOSITORY -u $DOCKER_USERNAME -p $DOCKER_PASSWORD | grep $COMMIT_SHA | cut -d \" -f 2) |
| 32 | + [ -z "$image_tag" ] && { echo "An image could not be found for the commit $COMMIT_SHA"; exit 1; } |
| 33 | + echo "Discovered image $image_tag" |
| 34 | + echo "Logging in to $DOCKER_REGISTRY_URL" |
| 35 | + docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL |
| 36 | + full_image="$DOCKER_REGISTRY_URL/$DOCKER_REPOSITORY:$image_tag" |
| 37 | + echo "Pulling image $full_image" |
| 38 | + docker pull $full_image |
| 39 | + full_backup_image="$BACKUP_DOCKER_REGISTRY_URL/$BACKUP_DOCKER_REPOSITORY:$BACKUP_IMAGE_TAG" |
| 40 | + echo "Setting image tag to $full_backup_image" |
| 41 | + docker tag $full_image $full_backup_image |
| 42 | + echo "Logging in to $BACKUP_DOCKER_REGISTRY_URL" |
| 43 | + docker login -u $BACKUP_DOCKER_USERNAME -p $BACKUP_DOCKER_PASSWORD $BACKUP_DOCKER_REGISTRY_URL |
| 44 | + echo "Pushing image $full_backup_image" |
| 45 | + docker image push $full_backup_image |
0 commit comments