Skip to content

Commit

Permalink
Run smoke test on image (#80)
Browse files Browse the repository at this point in the history
* WIP: smoke test on docker build

* Run by image id

* copy vendor dir

* Skip push on PR

* Rename cd job
  • Loading branch information
jvansanten authored Nov 7, 2024
1 parent d1a77cb commit 815eef0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/dockerhub.yaml → .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ on:
push:
tags:
- 'v*'
branches:
- main
pull_request:
branches:
- main

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

jobs:
publish:
container:

runs-on: ubuntu-24.04

Expand All @@ -32,18 +37,25 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
id: docker_build
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
load: true
- name: Smoke test
run: |
docker run --rm ${{ steps.docker_build.outputs.imageid }} python -c "from app import main"
- name: Extract metadata (tags, labels) for Docker
if: github.event_name != 'pull_request'
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 != 'pull_request'
id: docker_push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6
with:
push: true
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ RUN pip install "poetry==$POETRY_VERSION"
RUN python -m venv /venv

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

COPY app app
COPY README.md README.md
COPY vendor vendor
COPY README.md ./
RUN poetry build && /venv/bin/pip install dist/*.whl

FROM base AS final

# create cache dirs for astropy and friends
RUN mkdir -p --mode a=rwx /var/cache/astropy
ENV XDG_CACHE_HOME=/var/cache XDG_CONFIG_HOME=/var/cache
ENV XDG_CACHE_HOME=/var/cache XDG_CONFIG_HOME=/var/cache PATH=/venv/bin:$PATH

COPY --from=builder /venv /venv
CMD ["/venv/bin/uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Expand Down

0 comments on commit 815eef0

Please sign in to comment.