Skip to content

Update main.py

Update main.py #35

Workflow file for this run

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"