Skip to content

Commit 7697b5e

Browse files
authored
Merge pull request #136 from eScienceLab/135-add-release-triggered-github-actions-workflow-to-build-docker-image-with-baked-in-profiles
Added dockerfile and workflow to build Docker image with baked-in five-safes profile
2 parents 6ff7ea3 + 94dd10a commit 7697b5e

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Create and publish a Docker image (with profiles)
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}-fivesafes-profile
11+
12+
jobs:
13+
build-and-push-image:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
id-token: write
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract metadata (tags, labels) for Docker
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
37+
- name: Build and push Docker image
38+
id: push
39+
uses: docker/build-push-action@v6
40+
with:
41+
context: .
42+
file: ./Dockerfile.fivesafes-profile
43+
push: true
44+
tags: ${{ steps.meta.outputs.tags }}
45+
labels: ${{ steps.meta.outputs.labels }}
46+
47+
- name: Generate artifact attestation
48+
uses: actions/attest-build-provenance@v2
49+
with:
50+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
51+
subject-digest: ${{ steps.push.outputs.digest }}
52+
push-to-registry: true

Dockerfile.fivesafes-profile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.11-slim
2+
3+
ARG FIVE_SAFES_PROFILE_VERSION=five-safes-0.7.4-beta
4+
ARG PROFILES_ARCHIVE_URL=https://github.com/eScienceLab/rocrate-validator/archive/refs/tags/${FIVE_SAFES_PROFILE_VERSION}.tar.gz
5+
ARG PY_VER=3.11
6+
7+
# Install required system packages, including git
8+
RUN apt-get update && apt-get install -y git wget && rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /app
11+
12+
COPY requirements.txt .
13+
RUN pip install --upgrade pip
14+
RUN pip install --no-cache-dir -r requirements.txt
15+
16+
COPY cratey.py LICENSE /app/
17+
COPY app /app/app
18+
RUN <<EOF_WRF
19+
wget -O /tmp/rocrate-validator-profiles.tar.gz "$PROFILES_ARCHIVE_URL"
20+
tar -xzf /tmp/rocrate-validator-profiles.tar.gz \
21+
-C /usr/local/lib/python${PY_VER}/site-packages/rocrate_validator/profiles/ \
22+
--strip-components=3 \
23+
"rocrate-validator-${FIVE_SAFES_PROFILE_VERSION}/rocrate_validator/profiles/five-safes-crate"
24+
rm /tmp/rocrate-validator-profiles.tar.gz
25+
EOF_WRF
26+
27+
RUN useradd -ms /bin/bash flaskuser
28+
RUN chown -R flaskuser:flaskuser /app
29+
30+
ENV FIVE_SAFES_PROFILE_VERSION=${FIVE_SAFES_PROFILE_VERSION}
31+
32+
USER flaskuser
33+
34+
EXPOSE 5000
35+
36+
CMD ["flask", "run", "--host=0.0.0.0"]
37+
38+
LABEL org.opencontainers.image.source="https://github.com/eScienceLab/Cratey-Validator"
39+
LABEL org.cratey.five-safes-profile-version="${FIVE_SAFES_PROFILE_VERSION}"

0 commit comments

Comments
 (0)