Skip to content

Commit

Permalink
Update deploy action
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
matteocontrini committed Oct 25, 2023
1 parent 9408c5c commit 76c89e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ echo DOCKER_TAG=$DOCKER_TAG > .env
echo HOSTNAME=$HOSTNAME >> .env
docker-compose -f docker-compose.prod.yml pull
docker-compose -f docker-compose.prod.yml -p $CONTAINER_NAME up -d --force-recreate --remove-orphans
exit
22 changes: 6 additions & 16 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,16 @@ jobs:
build-and-push:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v1

uses: aws-actions/amazon-ecr-login@v2
- name: Build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
push: true
file: Dockerfile.Prod
Expand All @@ -31,27 +25,23 @@ jobs:
runs-on: ubuntu-latest
needs: build-and-push
steps:

- name: Checkout
uses: actions/checkout@v2

uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Prepare deploy
run: |
mkdir -p ~/.ssh/
echo "${{ secrets.DEPLOY_KNOWN_HOSTS }}" > ~/.ssh/known_hosts
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/key
chmod 0600 ~/.ssh/*
- name: Deploy
run: |
export DOCKER_REGISTRY_NAME="${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com"
export DOCKER_REGISTRY_TOKEN="$(aws ecr get-login-password --region ${{ secrets.AWS_REGION }})"
ssh ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_IP }} -i ~/.ssh/key DOCKER_REGISTRY_TOKEN=$DOCKER_REGISTRY_TOKEN DOCKER_REGISTRY_NAME=$DOCKER_REGISTRY_NAME DOCKER_TAG=${{ github.sha }} CONTAINER_NAME=${{ secrets.AWS_REPOSITORY }} 'bash -s' < .github/workflows/deploy.sh
ssh ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_IP }} -i ~/.ssh/key DOCKER_REGISTRY_TOKEN=$DOCKER_REGISTRY_TOKEN DOCKER_REGISTRY_NAME=$DOCKER_REGISTRY_NAME DOCKER_TAG=${{ github.sha }} CONTAINER_NAME=${{ secrets.AWS_REPOSITORY }} 'bash -s' < .github/workflows/deploy.sh

0 comments on commit 76c89e1

Please sign in to comment.