feat: it fixes old containers problem in deploy workflow #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file | |
run: echo "${{ secrets.VITE_INTERVIEW_API_URL }}" > .env | |
- 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.IMAGE_NAME }} | |
sudo docker rm ${{ env.IMAGE_NAME }} | |
sudo docker rmi ${{ env.IMAGE_NAME }} | |
sudo docker pull ${{ env.IMAGE_NAME }} | |
sudo docker run -d -p 80:80 ${{ env.IMAGE_NAME }} |