Update main.yml #52
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: 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 build . -f ./Dockerfile -t fivlao/sound:latest-dev | |
- name: Save Docker image as tar file | |
run: | | |
docker save -o fivlao-sound.tar fivlao/sound:latest-dev | |
touch file.txt | |
pwd | |
ls | |
- name: Transfer Docker image to remote server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
source: "file.txt" | |
target: "/home/ubuntu" | |
- name: Run new image version | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
username: ${{ secrets.EC2_USERNAME }} | |
host: ${{ secrets.EC2_HOST }} | |
script: | | |
sudo docker load -i "/home/ubuntu/fivlao-sound.tar" | |
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 fivlao/sound:latest-dev |