Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build container #29

Merged
merged 1 commit into from
Nov 11, 2024
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
44 changes: 31 additions & 13 deletions .github/workflows/container.yaml → .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,31 @@ on:
push:
tags:
- 'v*'
branches:
- main
- renovate/*
paths:
- pyproject.toml
- poetry.lock
- Dockerfile
- .github/workflows/cd.yaml
- ampel/**
pull_request:
branches:
- main
paths:
- pyproject.toml
- poetry.lock
- Dockerfile
- .github/workflows/cd.yaml
- ampel/**

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
publish:
container:

runs-on: ubuntu-24.04

Expand All @@ -21,39 +39,39 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3
- name: Login to Github Packages
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: lowercase github.repository
run: |
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV}
- name: Build
id: docker_build
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
load: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
- run: |
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test /venv/bin/python -c "import ampel.ztf.archive.server.app"
- name: Smoke test
run: |
container=$(docker run -d "${{ steps.docker_build.outputs.imageid }}")
sleep 1
docker stop -s INT -t 5 $container
docker logs $container
exit $(docker wait $container)
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push
id: docker_build
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
id: docker_push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# renovate: datasource=conda depName=conda-forge/python
# renovate: datasource=python-version depName=python versioning=python
ARG PYTHON_VERSION=3.12.6

FROM python:$PYTHON_VERSION-slim AS base
Expand All @@ -9,7 +9,7 @@ WORKDIR /app
FROM base AS builder

# renovate: datasource=pypi depName=poetry versioning=pep440
ARG POETRY_VERSION=1.8.3
ARG POETRY_VERSION=1.8.4

ENV PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
Expand All @@ -21,7 +21,7 @@ RUN python -m venv /venv
RUN apt-get update && apt-get install -y build-essential libpq-dev && rm -rf /var/lib/apt/lists/*

COPY pyproject.toml poetry.lock ./
RUN VIRTUAL_ENV=/venv poetry install --no-root --all-extras
RUN VIRTUAL_ENV=/venv poetry install --no-root --no-directory --all-extras --without dev

COPY ampel ampel
COPY README.md README.md
Expand All @@ -36,6 +36,6 @@ ENV XDG_CACHE_HOME=/var/cache XDG_CONFIG_HOME=/var/cache
RUN apt-get update && apt-get install -y libpq5 && rm -rf /var/lib/apt/lists/*

COPY --from=builder /venv /venv
CMD ["/venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
CMD ["/venv/bin/uvicorn", "ampel.ztf.archive.server.app:app", "--host", "0.0.0.0", "--port", "80"]

EXPOSE 80
Loading