Skip to content

Commit

Permalink
Updated the workflow to try deployement using docker locally
Browse files Browse the repository at this point in the history
  • Loading branch information
flokapi committed Sep 17, 2024
1 parent 60a070d commit 3485323
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 63 deletions.
136 changes: 75 additions & 61 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,98 @@ name: Build and Deploy Code
on: [push, pull_request]

jobs:
test:
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}}
# test:
# 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
# # 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: install
# run: make install
# - name: test
# run: make test

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: install
run: make install
- 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: 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: 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 }}/fastapi: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 }}
# # - 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 }}/fastapi: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: [test]
# needs: [test]
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: /root/image-classification
file_name: .env
fail_on_empty: false
sort_keys: false

- name: install
run: make install

- name: build
run: make build

- name: SCP repo to remote server
- name: SCP repo to production server
uses: appleboy/scp-action@master
with:
host: ${{ secrets.PROD_HOST }}
Expand All @@ -91,11 +103,13 @@ jobs:
source: "./*"
target: "/root/image-classification"

- name: deploy to ubuntu server
- name: deploy to production server
uses: appleboy/ssh-action@master
with:
host: ${{secrets.PROD_HOST}}
username: ${{secrets.PROD_USERNAME}}
password: ${{secrets.PROD_PASSWORD}}
script: |
echo ${{secrets.PROD_PASSWORD}} | sudo -S systemctl restart image-classification
docker build -t img_cls:latest .
docker run --rm img_cls:latest
# echo ${{secrets.PROD_PASSWORD}} | sudo -S systemctl restart image-classification
4 changes: 2 additions & 2 deletions app/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic_settings import BaseSettings
from pydantic_settings import BaseSettings,
from pydantic import ConfigDict


Expand All @@ -10,7 +10,7 @@ class Settings(BaseSettings):
loss_plot_file_name: str = "loss_plot.png"
accuracy_plot_file_name: str = "accuracy_plot.png"

model_config = ConfigDict(env_file=".env")
model_config = ConfigDict(env_file=".env", extra='allow')


settings = Settings()

0 comments on commit 3485323

Please sign in to comment.