Skip to content

Commit 4ad0f02

Browse files
committed
docker
1 parent d554e78 commit 4ad0f02

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
8+
jobs:
9+
build:
10+
name: Build and push 🚢
11+
runs-on: ubuntu-22.04
12+
permissions:
13+
packages: write
14+
contents: read
15+
attestations: write
16+
id-token: write
17+
env:
18+
REPO: ${{ github.event.repository.name }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Prepare environment
24+
run: |
25+
TAG=$(echo ${{ github.ref_name }} | sed 's/^v//')
26+
echo "TAG=$TAG" >> $GITHUB_ENV
27+
echo "The tag for this build is $TAG"
28+
echo "The repo name is: $REPO"
29+
30+
- id: auth-google
31+
uses: google-github-actions/auth@v2
32+
with:
33+
token_format: access_token
34+
project_id: 'open-targets-eu-dev'
35+
workload_identity_provider: projects/426265110888/locations/global/workloadIdentityPools/github-actions/providers/opentargets
36+
service_account: github-actions@open-targets-eu-dev.iam.gserviceaccount.com
37+
access_token_lifetime: 300s
38+
39+
- id: auth-gar
40+
name: Login to Google Artifact Registry
41+
uses: docker/login-action@v3
42+
with:
43+
registry: europe-west1-docker.pkg.dev
44+
username: oauth2accesstoken
45+
password: ${{ steps.auth-google.outputs.access_token }}
46+
47+
- id: auth-ghcr
48+
name: Log in to GitHub Container Registry
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- id: push
56+
name: Build and push Docker image
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
push: true
61+
tags: |
62+
ghcr.io/${{ github.repository }}:latest
63+
ghcr.io/${{ github.repository }}:${{ env.TAG }}
64+
europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }}:latest
65+
europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }}:${{ env.TAG }}
66+
67+
- id: generate-attestations
68+
name: Generate artifact attestation
69+
uses: actions/attest-build-provenance@v2
70+
with:
71+
subject-name: europe-west1-docker.pkg.dev/open-targets-eu-dev/${{ env.REPO }}/${{ env.REPO }}
72+
subject-digest: ${{ steps.push.outputs.digest }}
73+
push-to-registry: true

Dockerfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
FROM python:3.12-slim
22

3+
WORKDIR /app
4+
35
# Install uv
46
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
57

6-
# Copy the application into the container
7-
COPY . /app
8+
# Copy dependency files first for better caching
9+
COPY pyproject.toml uv.lock ./
810

9-
# Install the application dependencie
10-
WORKDIR /app
11+
# Install the application dependencies
1112
RUN uv sync --frozen --no-cache
1213

14+
# Copy the rest of the application
15+
COPY . .
16+
17+
EXPOSE 80
1318
CMD ["/app/.venv/bin/fastapi", "run", "app/main.py", "--port", "80", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)