From 77c7339d35f8ef136cb24786cd356e9e8e0d9c19 Mon Sep 17 00:00:00 2001 From: Cyrille Derche Date: Fri, 13 Sep 2024 19:06:09 +0200 Subject: [PATCH] Dockerfile --- .github/workflows/ci.yml | 42 +++++++++++++++++++++++++++++--- Dockerfile | 8 ++++++ main.py => app/main.py | 0 test_main.py => app/test_main.py | 0 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 Dockerfile rename main.py => app/main.py (100%) rename test_main.py => app/test_main.py (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ede33c..5c9cbe5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,9 +8,13 @@ on: branches: - main +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: - test: - name: Lint & Test + lint-test: + name: Lint + Test App runs-on: ubuntu-latest steps: @@ -33,5 +37,35 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest - run: | - pytest \ No newline at end of file + uses: paambaati/codeclimate-action@v2.2.4 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: pytest + + build-push: + name: Build + Push Image + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - uses: docker/build-push-action@v5 + with: + context: . + target: prod + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..01a02a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# It's recommended that we use `bullseye` for Python (alpine isn't suitable as it conflcts with numpy) +FROM python:3.12-bullseye AS base +WORKDIR /project +COPY . . +RUN pip3 install -no-cache-dir --upgrade -r requirements.txt + +FROM base AS prod +CMD ["fastapi", "run", "app/main.py", "--port", "80"] \ No newline at end of file diff --git a/main.py b/app/main.py similarity index 100% rename from main.py rename to app/main.py diff --git a/test_main.py b/app/test_main.py similarity index 100% rename from test_main.py rename to app/test_main.py