Skip to content

Update main.yml

Update main.yml #18

Workflow file for this run

name: build-deploy
on:
push:
branches: [ "dev", "main" ]
pull_request:
branches: [ "dev", "main" ]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build Docker image
run: |
docker login --username=fivlao --password=${{ secrets.DOCKER_ACCESS_TOKEN }} ghcr.io
docker build . -f ./Dockerfile -t fivlao/sound:latest-dev
echo ${{ secrets.EC2_PRIVATE_KEY }} > key.pem
cat key.pem
docker save fivlao/sound:latest-dev | ssh -i key.pem -C ${{ secrets.EC2_USERNAME }}@${{ secrets.EC2_HOST }} sudo docker load
- name: Deploy to EC2 instance
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
sudo docker stop prometei-rest-api || true
sudo docker rm prometei-rest-api || true
sudo docker run -d --name=prometei-rest-api -p 80:80 ghcr.io/fivlao/sound:latest-dev