Skip to content

Commit

Permalink
fix: deploy to prod (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsbergPhilip authored Nov 14, 2024
1 parent 5c0d19c commit 7d3ee40
Showing 1 changed file with 64 additions and 60 deletions.
124 changes: 64 additions & 60 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ jobs:
steps:
- run: echo "Ref ${{ github.ref }}"

- uses: actions/checkout@v1
- name: Checkout code
uses: actions/checkout@v4

- name: Build docker image
run: |
docker build -t diamonds2_base:latest -f .docker/dockerfiles/base .
docker-compose -f docker-compose.yml build
docker compose -f docker-compose.yml build
# Build and push production images
build-prod:
Expand All @@ -63,11 +64,14 @@ jobs:
needs:
- test-backend
steps:
- uses: actions/checkout@v1
- name: Checkout code
uses: actions/checkout@v4

- name: Build docker image
run: |
docker build -t diamonds2_base:latest -f .docker/dockerfiles/base .
docker-compose -f docker-compose.prod-build.yml build
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
Expand All @@ -88,59 +92,59 @@ jobs:
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
# deploy-prod:
# name: Deploy to new account
# needs: build-prod
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/master'
# steps:
# - uses: chrnorm/deployment-action@releases/v1
# name: Create GitHub deployment
# id: deployment
# with:
# token: "${{ github.token }}"
# target_url: https://diamonds.etimo.se
# environment: prod
# initial_status: "in_progress"
# - name: Update apps
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.DEPLOY_ETIMO_AWS_HOST }}
# USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }}
# PORT: 22
# KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }}
# script: |
# cd diamonds2
# git fetch
# git checkout --progress --force ${{ github.sha }}
# docker-compose down
# docker system prune -af
# source ~/.bash_profile
# DIAMONDS_DOCKER_TAG=master-${{ github.sha }} docker-compose -f docker-compose.prod-run.yml up -d
# - name: Update autoscaler
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.DEPLOY_ETIMO_AWS_AUTOSCALER_HOST }}
# USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }}
# PORT: 22
# KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }}
# script: |
# cd diamonds2
# git fetch
# git checkout --progress --force ${{ github.sha }}
# - name: Update deployment status (success)
# if: success()
# uses: chrnorm/deployment-status@releases/v1
# with:
# token: "${{ github.token }}"
# 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
# with:
# token: "${{ github.token }}"
# target_url: https://diamonds.etimo.se
# state: "failure"
# deployment_id: ${{ steps.deployment.outputs.deployment_id }}
deploy-prod:
name: Deploy to new account
needs: build-prod
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: chrnorm/deployment-action@releases/v1
name: Create GitHub deployment
id: deployment
with:
token: "${{ github.token }}"
target_url: https://diamonds.etimo.se
environment: prod
initial_status: "in_progress"
- name: Update apps
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_ETIMO_AWS_HOST }}
USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }}
PORT: 22
KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }}
script: |
cd diamonds2
git fetch
git checkout --progress --force ${{ github.sha }}
docker-compose down
docker system prune -af
source ~/.bash_profile
DIAMONDS_DOCKER_TAG=master-${{ github.sha }} docker-compose -f docker-compose.prod-run.yml up -d
- name: Update autoscaler
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEPLOY_ETIMO_AWS_AUTOSCALER_HOST }}
USERNAME: ${{ secrets.DEPLOY_ETIMO_AWS_USERNAME }}
PORT: 22
KEY: ${{ secrets.DEPLOY_ETIMO_AWS_KEY }}
script: |
cd diamonds2
git fetch
git checkout --progress --force ${{ github.sha }}
- name: Update deployment status (success)
if: success()
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
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
with:
token: "${{ github.token }}"
target_url: https://diamonds.etimo.se
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}

0 comments on commit 7d3ee40

Please sign in to comment.