From e5591dd0eb72a747ee688809188f34a94ee23481 Mon Sep 17 00:00:00 2001 From: Daniel Winther Date: Fri, 15 Nov 2024 11:34:44 +0100 Subject: [PATCH] fix: ghcr for docker images (#349) --- .github/workflows/main.yml | 47 +++++++++++++++++++++++-------------- docker-compose.prod-run.yml | 4 ++-- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ae06a8f..b1cc3f52 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -67,6 +67,13 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Login to GitHub registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build docker image run: | docker build -t diamonds2_base:latest -f .docker/dockerfiles/base . @@ -74,26 +81,25 @@ jobs: - name: Extract branch name shell: bash - run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV - - name: Print current branch name - run: echo "${BRANCH_NAME}" - - name: Docker login - run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin + run: | + echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//_/g')" >> $GITHUB_ENV + echo "${BRANCH_NAME}" + - name: Tag docker images run: | - docker tag diamonds2-frontend etimodanielwinther/diamonds2_frontend:latest-${BRANCH_NAME} - docker tag diamonds2-frontend etimodanielwinther/diamonds2_frontend:${BRANCH_NAME}-${{ github.sha }} - docker tag diamonds2-backend etimodanielwinther/diamonds2_backend:latest-${BRANCH_NAME} - docker tag diamonds2-backend etimodanielwinther/diamonds2_backend:${BRANCH_NAME}-${{ github.sha }} + docker tag diamonds2-frontend ghcr.io/etimo/diamonds2/frontend:latest-${BRANCH_NAME} + docker tag diamonds2-frontend ghcr.io/etimo/diamonds2/frontend:${BRANCH_NAME}-${{ github.sha }} + docker tag diamonds2-backend ghcr.io/etimo/diamonds2/backend:latest-${BRANCH_NAME} + docker tag diamonds2-backend ghcr.io/etimo/diamonds2/backend:${BRANCH_NAME}-${{ github.sha }} - name: Push docker images run: | - docker push etimodanielwinther/diamonds2_frontend:latest-${BRANCH_NAME} - docker push etimodanielwinther/diamonds2_frontend:${BRANCH_NAME}-${{ github.sha }} - docker push etimodanielwinther/diamonds2_backend:latest-${BRANCH_NAME} - docker push etimodanielwinther/diamonds2_backend:${BRANCH_NAME}-${{ github.sha }} - # When pushing code to master we want to deploy latest master images to test environment + docker push ghcr.io/etimo/diamonds2/frontend:latest-${BRANCH_NAME} + docker push ghcr.io/etimo/diamonds2/frontend:${BRANCH_NAME}-${{ github.sha }} + docker push ghcr.io/etimo/diamonds2/backend:latest-${BRANCH_NAME} + docker push ghcr.io/etimo/diamonds2/backend:${BRANCH_NAME}-${{ github.sha }} + deploy-prod: - name: Deploy to new account + name: Deploy to production needs: build-prod runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' @@ -106,8 +112,9 @@ jobs: target_url: https://diamonds.etimo.se environment: prod initial_status: "in_progress" + - name: Update apps - uses: appleboy/ssh-action@master + uses: appleboy/ssh-action@v1 with: host: ${{ secrets.DEPLOY_ETIMO_AWS_HOST }} USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} @@ -120,9 +127,11 @@ jobs: docker compose down --remove-orphans docker system prune -af source ~/.bash_profile - DIAMONDS_DOCKER_TAG=main-${{ github.sha }} docker compose -f docker-compose.prod-run.yml up -d + echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin + DIAMONDS_DOCKER_TAG=main-${{ github.sha }} docker-compose -f docker-compose.prod-run.yml up -d + - name: Update autoscaler - uses: appleboy/ssh-action@master + uses: appleboy/ssh-action@v1 with: host: ${{ secrets.DEPLOY_ETIMO_AWS_AUTOSCALER_HOST }} USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }} @@ -132,6 +141,7 @@ jobs: cd diamonds2 git fetch git checkout --progress --force ${{ github.sha }} + - name: Update deployment status (success) if: success() uses: chrnorm/deployment-status@releases/v1 @@ -140,6 +150,7 @@ jobs: target_url: https://diamonds.etimo.se state: "success" deployment_id: ${{ steps.deployment.outputs.deployment_id }} + - name: Update deployment status (failure) if: failure() uses: chrnorm/deployment-status@releases/v1 diff --git a/docker-compose.prod-run.yml b/docker-compose.prod-run.yml index e57abe81..57adacb4 100644 --- a/docker-compose.prod-run.yml +++ b/docker-compose.prod-run.yml @@ -2,7 +2,7 @@ version: "3.7" services: frontend: - image: etimodanielwinther/diamonds2_frontend:${DIAMONDS_DOCKER_TAG} + image: ghcr.io/etimo/diamonds2/rontend:${DIAMONDS_DOCKER_TAG} restart: always environment: - VITE_API_BASE_URL=http://backend:3000/api @@ -27,7 +27,7 @@ services: - ./data/certbot/www:/var/www/certbot backend: - image: etimodanielwinther/diamonds2_backend:${DIAMONDS_DOCKER_TAG} + image: ghcr.io/etimo/diamonds2/backend:${DIAMONDS_DOCKER_TAG} restart: always environment: - DATABASE_URL