Skip to content

Update main.yml

Update main.yml #60

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 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
chmod 664 fivlao-sound.tar
touch file.txt
pwd
ls
- name: Init AWS CLI
run: |
mkdir ~/aws
echo "${{ secrets.AWS_CONFIG }}" > ~/aws/config
echo "${{ secrets.AWS_CREDS }}" > ~/aws/credentials
- name: Start AWS EC2 instance
run: |
aws ec2 start-instances --instance-ids ${{ secrets.INSTANCE_ID }}
sleep 60
- 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: "fivlao-sound.tar"
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
- name: Stop AWS EC2 instance
run: aws ec2 stop-instances --instance-ids ${{ secrets.INSTANCE_ID }}