Skip to content

Commit

Permalink
feat(ci): use same registry for prod and staging images
Browse files Browse the repository at this point in the history
DEVOPS-77
  • Loading branch information
remdub committed Jun 29, 2024
1 parent 2e6d679 commit 193b8ce
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Update bookworm images in Harbor
name: Update images in Harbor
on:
schedule:
- cron: '0 5 * * 0' # Weekly on Sundays at 05:00
workflow_dispatch:
workflow_dispatch:IMAGE_NAME
env:
IMAGE_NAME: teleservices/bookworm
DEBIAN_VERSION: bookworm

jobs:
bookworm-staging:
staging:
runs-on:
group: self-hosted
steps:
Expand All @@ -14,42 +18,40 @@ jobs:
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Harbor prod registry
- name: Login to Harbor registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.HARBOR_URL_PROD }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME_PROD }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD_PROD }}
- name: Login to Harbor staging registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.HARBOR_URL_STAGING }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME_STAGING }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD_STAGING }}
- name: Build push bookworm image to staging registry
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD }}
- name: Build push image to registry
uses: docker/[email protected]
with:
context: teleservices
file: teleservices/Dockerfile
tags: ${{ secrets.HARBOR_URL_STAGING }}/teleservices/bookworm:latest
tags: |
${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:staging
${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:staging-${{ env.$GITHUB_RUN_NUMBER }}
platforms: linux/amd64
pull: true
push: true
target: prod-image
build-args: |
DEBIAN_VERSION=bookworm
- name: Build push bookworm-test image to staging registry
DEBIAN_VERSION=$DEBIAN_VERSION
- name: Build push test image to registry
uses: docker/[email protected]
with:
context: teleservices
file: teleservices/Dockerfile
tags: ${{ secrets.HARBOR_URL_STAGING }}/teleservices/bookworm-test:latest
tags: |
${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:staging
${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:staging-${{ env.$GITHUB_RUN_NUMBER }}
platforms: linux/amd64
pull: true
push: true
target: prod-image
target: dev-image
build-args: |
DEBIAN_VERSION=bookworm
DEBIAN_VERSION=$DEBIAN_VERSION
- name: Install curl
run: sudo apt-get update && sudo apt-get install -y curl
- name: Restart staging instance
Expand All @@ -58,10 +60,10 @@ jobs:
- name : Send notification on Mattermost
run: |
JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
MESSAGE="docker image has been updated on staging registry and the staging instance has been restarted. [Click here to see job on GitHub]($JOB_URL)"
MESSAGE="docker staging image has been updated on registry and the staging instance has been restarted. [Click here to see job on GitHub]($JOB_URL)"
curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ secrets.TELESERVICES_MATTERMOST_WEBHOOK_URL }}
bookworm-prod:
needs: [bookworm-staging]
production:
needs: [staging]
environment:
name: production
timeout-minutes: 2880
Expand All @@ -74,26 +76,24 @@ jobs:
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Harbor prod registry
- name: Login to Harbor registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.HARBOR_URL_PROD }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME_PROD }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD_PROD }}
- name: Login to Harbor staging registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.HARBOR_URL_STAGING }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME_STAGING }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD_STAGING }}
- name: Deploying image to prod registry
run: echo "Deploying image to prod registry"
- name: Pull Image from staging registry
run: docker pull ${{ secrets.HARBOR_URL_STAGING }}/teleservices/bookworm:latest
- name: Tag image for prod registry
run: docker tag ${{ secrets.HARBOR_URL_STAGING }}/teleservices/bookworm:latest ${{ secrets.HARBOR_URL_PROD }}/teleservices/bookworm:latest
- name: Push image to prod registry
run: docker push ${{ secrets.HARBOR_URL_PROD }}/teleservices/bookworm:latest
registry: ${{ secrets.HARBOR_URL }}
username: ${{ secrets.TELESERVICES_HARBOR_USERNAME }}
password: ${{ secrets.TELESERVICES_HARBOR_PASSWORD }}
- name: Tag prod images
run: |
docker tag ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:staging ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:latest
docker tag ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:latest ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:latest-${{ env.$GITHUB_RUN_NUMBER }}
docker tag ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:staging ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:latest
docker tag ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:latest ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:latest-${{ env.$GITHUB_RUN_NUMBER }}
- name: Push images to registry
run: |
docker push ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}:latest-${{ env.$GITHUB_RUN_NUMBER }}
docker push ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:latest
docker push ${{ secrets.HARBOR_URL }}/${{ env.IMAGE_NAME }}-test:latest-${{ env.$GITHUB_RUN_NUMBER }}
- name: Install curl
run: sudo apt-get update && sudo apt-get install -y curl
- name: Schedule restart of all prod instances
Expand All @@ -102,5 +102,5 @@ jobs:
- name : Send notification on Mattermost
run: |
JOB_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
MESSAGE="docker image has been updated on prod registry. [Click here to see job on GitHub]($JOB_URL) A reboot of all production instances has been scheduled for tomorrow at 1am. "
MESSAGE="docker prod image has been updated on registry. [Click here to see job on GitHub]($JOB_URL) A reboot of all production instances has been scheduled for tomorrow at 1am. "
curl -i -X POST -H 'Content-Type: application/json' -d "{\"text\": \"$MESSAGE\"}" ${{ secrets.TELESERVICES_MATTERMOST_WEBHOOK_URL }}

0 comments on commit 193b8ce

Please sign in to comment.