-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (38 loc) · 1.22 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
name: Publish CI
on:
push:
branches:
- main
env:
REGISTRY: ghcr.io
APP_IMAGE_NAME: 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: Build and Push Docker image
uses: docker/build-push-action@v2
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
repository: "${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}"
tag_with_ref: true
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 -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} ${{ env.REGISTRY }} &&
docker pull "${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}":latest &&
docker run -d --name ${{ env.APP_NAME }} -p 0.0.0.0:80:80 "${{ env.REGISTRY }}/${{ env.APP_IMAGE_NAME }}":latest