Skip to content

Commit

Permalink
ops: dockerize
Browse files Browse the repository at this point in the history
  • Loading branch information
kerberizer committed Aug 10, 2023
1 parent dede1ba commit 6f09e96
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: Build and publish the Docker image

on: # yamllint disable-line rule:truthy
push:
branches: ["develop"]
# Publish semver tags as releases.
tags: ['v*.*.*']
pull_request:
branches: ["develop"]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1
with:
cosign-release: 'v2.1.1'

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'develop') }}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.9-slim as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* /tmp/
COPY ./pynanomapper /tmp/pynanomapper
COPY ./ramanchada2 /tmp/ramanchada2

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM tiangolo/uvicorn-gunicorn:python3.9-slim

LABEL org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.description="RamanChada 2 API service" \
org.opencontainers.image.title="ramanchada-api" \
org.opencontainers.image.version="latest" \
org.opencontainers.image.vendor="IDEAconsult" \
org.opencontainers.image.source="https://github.com/h2020charisma/ramanchada-api" \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.url="https://github.com/h2020charisma/ramanchada-api/blob/main/README.md" \
org.opencontainers.image.schema-version="1.0"

COPY --from=requirements-stage /tmp/requirements.txt /app/requirements.txt
COPY ./pynanomapper /tmp/pynanomapper
COPY ./ramanchada2 /tmp/ramanchada2

RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

COPY ./app /app
24 changes: 24 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
networks:
ramanchada_api_dev:
name: ramanchada-api-dev

volumes:
uploads-dev:
driver: zfs
name: ${ZFSROOT}/ramanchada-api-uploads-dev

services:

develop:
image: ghcr.io/h2020charisma/ramanchada-api:develop
container_name: ramanchada-api-dev
hostname: ramanchada-api-dev
restart: unless-stopped
labels:
traefik.enable: 'true'
traefik.http.routers.ramanchada-api-dev.entrypoints: tcp80v4*,tcp443v4*,tcp80v6*,tcp443v6*
traefik.http.routers.ramanchada-api-dev.rule: Host(`api.ramanchada.ideaconsult.net`)
networks:
- ramanchada_api_dev
volumes:
- uploads-dev:/app/uploads

0 comments on commit 6f09e96

Please sign in to comment.