-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (48 loc) · 1.83 KB
/
build-deploy.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: Docker Image CI
env:
DOCKER_IMAGE_NAME: wseresearch/qa-systems-wrapper
DOCKER_CONTAINER_NAME: qa-systems-wrapper
on:
push:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Get current version
run: >
echo "X_APP_VERSION=$(cat < main.py | grep -Po '(?<=__version__ = \")([^\"]*)')" >> $GITHUB_ENV
- name: Build the Docker image for deployment
run: >
docker build --tag "$DOCKER_IMAGE_NAME:latest" .
- name: Tag image with specific version
run: >
docker tag "$DOCKER_IMAGE_NAME:latest" "$DOCKER_IMAGE_NAME:$X_APP_VERSION"
- name: Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push docker image with latest version
run: docker push "$DOCKER_IMAGE_NAME:latest"
- name: Push docker image with specific version
run: docker push "$DOCKER_IMAGE_NAME:$X_APP_VERSION"
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: SSH into server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
port: ${{ secrets.SERVER_PORT }}
envs: DOCKER_IMAGE_NAME,DOCKER_CONTAINER_NAME
script: |
docker stop "$DOCKER_CONTAINER_NAME" || true && docker rm "$DOCKER_CONTAINER_NAME" || true
echo "Pulling image: $DOCKER_IMAGE_NAME"
docker pull $DOCKER_IMAGE_NAME:latest
echo "Starting container: $DOCKER_CONTAINER_NAME"
docker run --restart=always -d -p 40199:8080 --name "$DOCKER_CONTAINER_NAME" "$DOCKER_IMAGE_NAME:latest"