Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/publish-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build and publish container image to GHCR

on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- main

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
env:
PR_IMAGE_TAG: ""

steps:
- name: Checkout
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: Log in to GHCR
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set image name
run: |
repo_lc=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=ghcr.io/${repo_lc}" >> "$GITHUB_ENV"

- name: Set PR image tag
if: github.event_name == 'pull_request'
run: |
ref_lc=$(echo "${GITHUB_HEAD_REF}" | tr '[:upper:]' '[:lower:]')
ref_sanitized=$(echo "${ref_lc}" | sed 's/[^a-z0-9_.-]/-/g')
echo "PR_IMAGE_TAG=${ref_sanitized}-pr-${{ github.event.pull_request.number }}" >> "$GITHUB_ENV"

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=${{ env.PR_IMAGE_TAG }},enable=${{ github.event_name == 'pull_request' }}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push (multi-arch)
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and load (single-arch)
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: false
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
21 changes: 20 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
na_emailer.egg-info
.venv/
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so
*.egg
*.egg-info/
dist/
build/
.pytest_cache/
.coverage
htmlcov/
.tox/
.git/
.gitignore
.idea/
*.md
config/
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
WORKDIR /app

COPY pyproject.toml README.md /app/
COPY app /app/app
COPY templates /app/templates

#install runtime deps (no venv inside container)
RUN pip install --no-cache-dir -U pip \
&& pip install --no-cache-dir .

COPY app /app/app
COPY templates /app/templates

ENV PORT=8080
EXPOSE 8080

CMD ["functions-framework", "--target", "handle", "--port", "8080"]
CMD ["functions-framework", "--target", "handle", "--source", "app/main.py", "--port", "8080"]