Skip to content

Commit c614353

Browse files
committed
Add GitHub Actions workflow for building and pushing Docker images on tag
1 parent 7ae524c commit c614353

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

.github/workflows/docker-build.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build & Push Docker Images on Tag
2+
on:
3+
push:
4+
tags:
5+
- 'v*' # Triggers only on tags like v0.1.2, v0.1.2.dev1, etc.
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-push:
10+
runs-on: ubuntu-latest
11+
env:
12+
IMAGE_BASE: isisacceleratorcontrols/poly-lithic
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Extract version from tag
18+
id: vars
19+
run: |
20+
TAG_NAME=${GITHUB_REF#refs/tags/}
21+
echo "VERSION=${TAG_NAME}" >> $GITHUB_ENV
22+
echo "version=${TAG_NAME}" >> $GITHUB_OUTPUT
23+
24+
- name: Log in to Docker Hub
25+
uses: docker/login-action@v3
26+
with:
27+
username: ${{ secrets.DOCKERHUB_USERNAME }}
28+
password: ${{ secrets.DOCKERHUB_TOKEN }}
29+
30+
- name: Build Docker images with version injection
31+
run: |
32+
docker build --pull --rm --target vanilla \
33+
--build-arg VERSION=${VERSION} \
34+
-f Dockerfile -t $IMAGE_BASE:base-${VERSION} .
35+
36+
docker build --pull --rm --target torch \
37+
--build-arg VERSION=${VERSION} \
38+
-f Dockerfile -t $IMAGE_BASE:torch-${VERSION} .
39+
40+
docker build --pull --rm --target tensorflow \
41+
--build-arg VERSION=${VERSION} \
42+
-f Dockerfile -t $IMAGE_BASE:tensorflow-${VERSION} .
43+
44+
- name: Push versioned images
45+
run: |
46+
docker push $IMAGE_BASE:base-${VERSION}
47+
docker push $IMAGE_BASE:torch-${VERSION}
48+
docker push $IMAGE_BASE:tensorflow-${VERSION}
49+
50+
- name: Tag and push latest if version is pure semver
51+
if: ${{ steps.vars.outputs.version =~ '^v[0-9]+\\.[0-9]+\\.[0-9]+$' }}
52+
run: |
53+
echo "Tag is a pure semver release — tagging latest"
54+
55+
docker tag $IMAGE_BASE:base-${VERSION} $IMAGE_BASE:base-latest
56+
docker tag $IMAGE_BASE:torch-${VERSION} $IMAGE_BASE:torch-latest
57+
docker tag $IMAGE_BASE:tensorflow-${VERSION} $IMAGE_BASE:tensorflow-latest
58+
docker tag $IMAGE_BASE:base-latest $IMAGE_BASE:latest
59+
60+
docker push $IMAGE_BASE:base-latest
61+
docker push $IMAGE_BASE:torch-latest
62+
docker push $IMAGE_BASE:tensorflow-latest
63+
docker push $IMAGE_BASE:latest

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Pipeline
1+
name: Main build and test workflow
22

33
# only on tagged commits or manual trigger or on change to main.yml
44
on:

Dockerfile

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,70 @@
1515
# # CMD tail -f /dev/null
1616
# Stage 1: Base image with common dependencies
1717

18+
# ===== Base stage =====
1819
FROM python:3.11.8-slim-bullseye AS base
20+
21+
# Accept version as build argument
22+
ARG VERSION=""
23+
ENV POLY_LITHIC_VERSION=$VERSION
24+
25+
LABEL org.opencontainers.image.version="${POLY_LITHIC_VERSION}"
26+
27+
# System dependencies
1928
RUN apt-get update && apt-get install -y --no-install-recommends \
2029
git \
2130
iputils-ping \
2231
curl \
2332
&& rm -rf /var/lib/apt/lists/*
2433

34+
# Python requirements
2535
COPY requirements.txt /app/requirements.txt
2636
RUN python -m pip install -r /app/requirements.txt --no-cache-dir
2737

38+
# Embed version into the container (optional)
39+
RUN echo "${POLY_LITHIC_VERSION}" > /opt/deployment/version.txt
2840

41+
# ===== Torch stage =====
2942
FROM base AS torch
30-
# Install additional ML libraries
43+
44+
# Additional ML dependencies
3145
RUN python -m pip install botorch pydantic torch==2.6.0 --no-cache-dir
32-
# need to copy poly_lithic, pyptoject.toml and tests
46+
47+
# Copy code
3348
COPY poly_lithic /opt/poly_lithic
3449
COPY pyproject.toml /opt/deployment/pyproject.toml
3550
COPY tests /opt/deployment/tests
51+
3652
WORKDIR /opt/deployment
53+
3754
RUN python -m pip install poly-lithic --no-cache-dir
3855

3956
CMD pl -c config.yaml -r -e env.json && pl --publish -c config.yaml -e env.json
4057

58+
# ===== TensorFlow stage =====
4159
FROM base AS tensorflow
42-
# Install additional ML libraries
60+
4361
RUN python -m pip install pydantic tensorflow --no-cache-dir
4462

4563
COPY poly_lithic /opt/poly_lithic
4664
COPY pyproject.toml /opt/deployment/pyproject.toml
4765
COPY tests /opt/deployment/tests
66+
4867
WORKDIR /opt/deployment
68+
4969
RUN python -m pip install poly-lithic --no-cache-dir
5070

5171
CMD pl -c config.yaml -r -e env.json && pl --publish -c config.yaml -e env.json
5272

53-
73+
# ===== Vanilla stage =====
5474
FROM base AS vanilla
5575

5676
COPY poly_lithic /opt/poly_lithic
5777
COPY pyproject.toml /opt/deployment/pyproject.toml
5878
COPY tests /opt/deployment/tests
79+
5980
WORKDIR /opt/deployment
81+
6082
RUN python -m pip install poly-lithic --no-cache-dir
6183

6284
CMD pl -c config.yaml -r -e env.json && pl --publish -c config.yaml -e env.json

0 commit comments

Comments
 (0)