Skip to content

Commit

Permalink
Merge pull request #3 from atrifat/feat-docker-support
Browse files Browse the repository at this point in the history
feat: docker image support
  • Loading branch information
atrifat authored Jun 7, 2024
2 parents 9a326d1 + c1731a7 commit 68eefd4
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build Docker Image

on:
push:
branches: ["main", "dev"]
tags: ["v*"]
workflow_dispatch:

env:
REGISTRY: ghcr.io

jobs:
build-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract Docker metadata
if: ${{ !env.ACT }}
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}

- name: Log into Container Registry
if: github.event_name != 'pull_request' && ${{ !env.ACT }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request' && ${{ !env.ACT }}
with:
context: .
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
47 changes: 47 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM python:3.10-bookworm as builder

WORKDIR /builder

RUN addgroup --gid 1000 user
RUN adduser --disabled-password --gecos '' --uid 1000 --gid 1000 user

ENV USER=user
ENV HOME=/home/user

RUN python3 -mvenv venv && ./venv/bin/pip install --no-cache-dir --upgrade pip

COPY requirements.txt requirements.txt

RUN ./venv/bin/pip install -U --no-cache-dir -r requirements.txt

FROM python:3.10-bookworm as runner

WORKDIR /app

RUN addgroup --gid 1000 user
RUN adduser --disabled-password --gecos '' --uid 1000 --gid 1000 user

ENV USER=user
ENV HOME=/home/user

COPY --from=builder --chown=user:user /builder/venv /app/venv

COPY --chown=user:user app.py app.py

RUN chown -R user:user /app && chown -R user:user /home/user

USER user

ENV ENABLE_API_TOKEN=false
ENV API_TOKEN=
ENV APP_ENV=production
ENV LISTEN_HOST=0.0.0.0
ENV LISTEN_PORT=5000
ENV LANGUAGE_DETECTION_MODEL=langdetect
ENV LOW_MEMORY_MODE=false
ENV ENABLE_CACHE=false
ENV CACHE_DURATION_SECONDS=60

EXPOSE $LISTEN_PORT

ENTRYPOINT [ "./venv/bin/python" , "app.py" ]

0 comments on commit 68eefd4

Please sign in to comment.