Skip to content

Commit 001b352

Browse files
authored
Feat: double step dockerfile (#687)
### Description Please explain the changes you made here. ### Checklist - [ ] Created tests which fail without the change (if possible) - [ ] All tests passing - [ ] Extended the documentation, if necessary
1 parent 9fe12d4 commit 001b352

File tree

4 files changed

+171
-67
lines changed

4 files changed

+171
-67
lines changed

.github/workflows/publish.yml

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,72 @@
1-
name: Build and Publish Hyperion Docker Images
2-
on:
3-
workflow_dispatch:
4-
push:
5-
tags:
6-
- 'v*.*.*'
7-
8-
jobs:
9-
docker:
10-
runs-on: ubuntu-latest
11-
timeout-minutes: 10
12-
13-
steps:
14-
- name: Check out the code
15-
uses: actions/checkout@v4
16-
17-
- name: Docker metadata
18-
id: meta
19-
uses: docker/metadata-action@v5
20-
with:
21-
images: ${{ secrets.DOCKER_REGISTRY_IDENTIFER }}/hyperion
22-
tags: |
23-
type=semver,pattern={{version}}
24-
type=semver,pattern={{major}}.{{minor}}
25-
26-
- name: Set up Docker Buildx
27-
uses: docker/setup-buildx-action@v3
28-
29-
- name: Login to GitHub Container Registry
30-
uses: docker/login-action@v3
31-
with:
32-
registry: ${{ secrets.DOCKER_REGISTRY_URL }}
33-
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
34-
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
35-
36-
- name: Build and push app
37-
uses: docker/build-push-action@v6
38-
with:
39-
context: .
40-
platforms: linux/amd64 #,linux/arm64
41-
push: true
42-
tags: ${{ steps.meta.outputs.tags }}
43-
labels: ${{ steps.meta.outputs.labels }}
44-
cache-from: type=gha
45-
cache-to: type=gha,mode=max
1+
name: Build and Publish Hyperion Docker Images
2+
on:
3+
workflow_dispatch:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
docker:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 10
12+
13+
steps:
14+
- name: Check out the code
15+
uses: actions/checkout@v4
16+
17+
- name: Calculate requirements md5
18+
run: |
19+
echo "REQUIREMENTS_MD5=$(cat requirements-common.txt requirements-prod.txt | md5sum | cut -d ' ' -f 1)" >> $GITHUB_ENV
20+
21+
- name: Check if base image exists
22+
run: |
23+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
24+
-u ${{ secrets.DOCKER_REGISTRY_USERNAME }}:${{ secrets.DOCKER_REGISTRY_PASSWORD }} \
25+
-H "Accept: application/vnd.oci.image.index.v1+json" \
26+
"${{ secrets.DOCKER_REGISTRY_URL }}/v2/hyperion-base/manifests/${{ env.REQUIREMENTS_MD5 }}")
27+
28+
echo "HTTP_CODE=$HTTP_CODE" >> $GITHUB_ENV
29+
30+
if [ "$HTTP_CODE" -ne 200 ]; then
31+
echo "Error: Base image not found, wait for the base image to be built first"
32+
exit 1
33+
fi
34+
35+
echo "EXISTS=true" >> $GITHUB_ENV
36+
37+
- name: Docker metadata
38+
if: env.EXISTS == 'true'
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ secrets.DOCKER_REGISTRY_IDENTIFER }}/hyperion
43+
tags: |
44+
type=semver,pattern={{version}}
45+
type=semver,pattern={{major}}.{{minor}}
46+
47+
- name: Set up Docker Buildx
48+
if: env.EXISTS == 'true'
49+
uses: docker/setup-buildx-action@v3
50+
51+
- name: Login to GitHub Container Registry
52+
if: env.EXISTS == 'true'
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ${{ secrets.DOCKER_REGISTRY_URL }}
56+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
57+
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
58+
59+
- name: Build and push app
60+
if: env.EXISTS == 'true'
61+
uses: docker/build-push-action@v6
62+
with:
63+
context: .
64+
platforms: linux/amd64 #,linux/arm64
65+
push: true
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
70+
build-args: |
71+
REQUIREMENTS_MD5=${{env.REQUIREMENTS_MD5}}
72+
DOCKER_REGISTRY_IDENTIFER=${{ secrets.DOCKER_REGISTRY_IDENTIFER }}

.github/workflows/publishbase.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Build and Publish Hyperion Base Docker Images
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- 'Dockerfile.base'
7+
- 'requirements-common.txt'
8+
- 'requirements-prod.txt'
9+
10+
11+
jobs:
12+
docker:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 10
15+
16+
steps:
17+
- name: Check out the code
18+
uses: actions/checkout@v4
19+
20+
- name: Calculate requirements md5
21+
run: |
22+
echo "REQUIREMENTS_MD5=$(cat requirements-common.txt requirements-prod.txt | md5sum | cut -d ' ' -f 1)" >> $GITHUB_ENV
23+
24+
- name: Check if image exists
25+
run: |
26+
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
27+
-u ${{ secrets.DOCKER_REGISTRY_USERNAME }}:${{ secrets.DOCKER_REGISTRY_PASSWORD }} \
28+
-H "Accept: application/vnd.oci.image.index.v1+json" \
29+
"${{ secrets.DOCKER_REGISTRY_URL }}/v2/hyperion-base/manifests/${{ env.REQUIREMENTS_MD5 }}")
30+
[ "$HTTP_CODE" -eq 200 ] && exists=true || exists=false
31+
echo "EXISTS=$exists" >> $GITHUB_ENV
32+
33+
34+
- name: Docker metadata
35+
if: env.EXISTS == 'false'
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ secrets.DOCKER_REGISTRY_IDENTIFER }}/hyperion-base
40+
tags: |
41+
${{ env.REQUIREMENTS_MD5 }}
42+
43+
- name: Set up Docker Buildx
44+
if: env.EXISTS == 'false'
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Login to GitHub Container Registry
48+
if: env.EXISTS == 'false'
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ${{ secrets.DOCKER_REGISTRY_URL }}
52+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
53+
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
54+
55+
- name: Build and push app
56+
if: env.EXISTS == 'false'
57+
uses: docker/build-push-action@v6
58+
with:
59+
context: .
60+
file: ./Dockerfile.base
61+
platforms: linux/amd64 #,linux/arm64
62+
push: true
63+
tags: ${{ steps.meta.outputs.tags }}
64+
labels: ${{ steps.meta.outputs.labels }}
65+
cache-from: type=gha
66+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
FROM ghcr.io/astral-sh/uv:python3.11-bookworm
2-
3-
ENV PYTHONDONTWRITEBYTECODE=1
4-
ENV PYTHONUNBUFFERED=1
5-
ENV UV_COMPILE_BYTECODE=1
6-
7-
WORKDIR /hyperion
8-
9-
COPY requirements-common.txt .
10-
COPY requirements-prod.txt .
11-
RUN uv pip install --system --no-cache-dir -r requirements-prod.txt
12-
13-
COPY init.py .
14-
COPY alembic.ini .
15-
COPY migrations migrations/
16-
COPY assets assets/
17-
COPY app app/
18-
19-
COPY start.sh .
20-
RUN chmod +x start.sh
21-
22-
ENTRYPOINT ["./start.sh"]
1+
ARG REQUIREMENTS_MD5
2+
ARG DOCKER_REGISTRY_IDENTIFER
3+
FROM ${DOCKER_REGISTRY_IDENTIFER}/hyperion-base:${REQUIREMENTS_MD5}
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
ENV PYTHONUNBUFFERED=1
7+
ENV UV_COMPILE_BYTECODE=1
8+
9+
WORKDIR /hyperion
10+
11+
COPY init.py .
12+
COPY alembic.ini .
13+
COPY migrations migrations/
14+
COPY assets assets/
15+
COPY app app/
16+
17+
COPY start.sh .
18+
RUN chmod +x start.sh
19+
20+
ENTRYPOINT ["./start.sh"]

Dockerfile.base

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm
2+
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
ENV UV_COMPILE_BYTECODE=1
6+
7+
WORKDIR /hyperion
8+
9+
COPY requirements-common.txt .
10+
COPY requirements-prod.txt .
11+
RUN uv pip install --system --no-cache-dir -r requirements-prod.txt
12+
13+
ENTRYPOINT ["/bin/bash"]

0 commit comments

Comments
 (0)