Skip to content

Commit

Permalink
fix: ghcr for docker images (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
indrif authored Nov 15, 2024
1 parent 6d5996c commit e5591dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
47 changes: 29 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,33 +67,39 @@ 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 .
docker compose -f docker-compose.prod-build.yml build
- 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'
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.prod-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e5591dd

Please sign in to comment.