-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (45 loc) · 1.53 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Publish CI
on:
push:
branches:
- main
permissions: write-all
env:
REGISTRY: ghcr.io
APP_IMAGE_NAME: rafaellevissa/bnb-bank-api
APP_NAME: bnb-bank-api
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Registry
if: success()
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:latest
deploy:
runs-on: ubuntu-latest
needs: build-and-push
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: SSH to EC2 and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
script: |
docker login ${{ env.REGISTRY }} -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} &&
docker pull ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:latest &&
docker inspect ${{ env.APP_NAME }} &> /dev/null && docker rm -f ${{ env.APP_NAME }} || true &&
docker run -d --name ${{ env.APP_NAME }} -p 8080:80 --env-file=/opt/bnb-bank/.env-backend --network bnb-bank ${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}:latest