Skip to content

Merge pull request #22 from matheusdoedev/feat/workflow #22

Merge pull request #22 from matheusdoedev/feat/workflow

Merge pull request #22 from matheusdoedev/feat/workflow #22

Workflow file for this run

name: Deploy to Amazon ECS
on:
push:
branches: ['master']
env:
CONTAINER_NAME: medical-supplier-manager
CONTAINER_TAG: latest
permissions:
contents: read
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout the files
uses: actions/checkout@v3
- name: Login to docker hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
- name: Configuring env production file
run: echo "VITE_INTERVIEW_API_URL=${{ secrets.VITE_INTERVIEW_API_URL }}" > .env.production
- name: Build docker image
run: docker build -t ${{ env.CONTAINER_NAME }} .
- name: Tag image
run: docker tag ${{ env.CONTAINER_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ env.CONTAINER_NAME }}:${{ env.CONTAINER_TAG }}
- name: Publish image to docker hub
run: docker push ${{ secrets.DOCKER_USERNAME }}/${{ env.CONTAINER_NAME }}:${{ env.CONTAINER_TAG }}
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
steps:
- name: SSH Deploy
uses: appleboy/ssh-action@master
env:
IMAGE_NAME: ${{ secrets.DOCKER_USERNAME }}/${{ env.CONTAINER_NAME }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: 22
script: |
sudo docker stop ${{ env.CONTAINER_NAME }}
sudo docker rm ${{ env.CONTAINER_NAME }}
sudo docker rmi ${{ env.IMAGE_NAME }}
sudo docker pull ${{ env.IMAGE_NAME }}
sudo docker run -d --name ${{ env.CONTAINER_NAME }} -p 80:80 ${{ env.IMAGE_NAME }}