Skip to content

Added README

Added README #26

Workflow file for this run

name: Build and Deploy Code
on: [push, pull_request]
jobs:
build:
environment:
name: testing
env:
TF_MODEL_EPOCHS: ${{vars.TF_MODEL_EPOCHS}}
IMAGE_SIZE_X: ${{vars.IMAGE_SIZE_X}}
IMAGE_SIZE_Y: ${{vars.IMAGE_SIZE_Y}}
# services:
# postgres:
# image: postgres
# env:
# POSTGRES_PASSWORD: ${{secrets.DATABASE_PASSWORD}}
# POSTGRES_DB: ${{secrets.DATABASE_NAME}}_test
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
runs-on: ubuntu-latest
steps:
- name: pulling git repo
uses: actions/checkout@v2
- name: Install packages
run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-glx
- name: Install python version 3.12
uses: actions/setup-python@v2
with:
python-version: "3.12"
- name: update pip
run: python -m pip install --upgrade pip
- name: Make app envfile
uses: SpicyPizza/create-envfile@v1
with:
envkey_TF_MODEL_EPOCHS: ${{ vars.TF_MODEL_EPOCHS }}
envkey_IMAGE_SIZE_X: ${{ vars.IMAGE_SIZE_X }}
envkey_IMAGE_SIZE_Y: ${{ vars.IMAGE_SIZE_Y }}
directory: .
file_name: .env
fail_on_empty: false
sort_keys: false
- name: install
run: make install
- name: build static files
run: make build-static-files
- name: test
run: make test
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/img_cls:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
deploy:
runs-on: ubuntu-latest
needs: [build]
environment:
name: production
steps:
# - name: pulling git repo
# uses: actions/checkout@v2
# - name: Make app envfile
# uses: SpicyPizza/create-envfile@v1
# with:
# envkey_TF_MODEL_EPOCHS: ${{ vars.TF_MODEL_EPOCHS }}
# envkey_IMAGE_SIZE_X: ${{ vars.IMAGE_SIZE_X }}
# envkey_IMAGE_SIZE_Y: ${{ vars.IMAGE_SIZE_Y }}
# directory: .
# file_name: .env
# fail_on_empty: false
# sort_keys: false
# - name: install
# run: make install
# - name: build
# run: make build
# - name: SCP repo to production server
# uses: appleboy/scp-action@master
# with:
# host: ${{ secrets.PROD_HOST }}
# username: ${{ secrets.PROD_USERNAME }}
# password: ${{ secrets.PROD_PASSWORD }}
# source: "./*"
# target: "/root/image-classification"
# - name: deploy to production server
# uses: appleboy/ssh-action@master
# with:
# host: ${{secrets.PROD_HOST}}
# username: ${{secrets.PROD_USERNAME}}
# password: ${{secrets.PROD_PASSWORD}}
# script: |
# cd /root/image-classification
# echo ${{secrets.PROD_PASSWORD}} | sudo -S systemctl restart image-classification
- name: deploy to production server
uses: appleboy/ssh-action@master
with:
host: ${{secrets.PROD_HOST}}
username: ${{secrets.PROD_USERNAME}}
password: ${{secrets.PROD_PASSWORD}}
script: |
cd /root/image-classification
docker ps -q --filter "name=img_cls_cont" | xargs -r docker stop
docker ps -a -q --filter "name=img_cls_cont" | xargs -r docker rm
# docker build -t img_cls:latest .
# docker run -p 8000:8000 -d --name img_cls_cont img_cls:latest
docker pull ${{secrets.DOCKER_HUB_USERNAME}}/img_cls:latest
docker run -p 8000:8000 -d --name img_cls_cont ${{secrets.DOCKER_HUB_USERNAME}}/img_cls:latest
docker image prune -af
# echo ${{secrets.PROD_PASSWORD}} | sudo -S systemctl restart image-classification