-
Notifications
You must be signed in to change notification settings - Fork 4
47 lines (39 loc) · 1.33 KB
/
docker-cicd.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
name: docker cicd
on:
push:
branches: [ "develop" ]
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }}
jobs:
build:
name: docker build
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- name: docker login
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
- name: build the docker image
run: |
docker build -t $DOCKER_USER/$DOCKER_IMAGE:latest .
- name: docker push
run: |
docker push $DOCKER_USER/$DOCKER_IMAGE:latest
deploy:
name: deploy to EC2
needs: build
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
script: |
docker pull ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE }}:latest
docker rm -f ${{ secrets.BE_CONTAINER }}
docker run -d -p ${{ secrets.BE_PORT }}:${{ secrets.BE_PORT }} --name ${{ secrets.BE_CONTAINER }} --network ${{ secrets.BE_NETWORK }} -v ${{ secrets.BE_VOLUME }} ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE }}:latest