Skip to content

Commit a3d1d13

Browse files
authored
Merge pull request #184 from AlexandrovLab/docker-ghcr
v1.0.2: Add automated Docker build and publish pipeline
2 parents 28d7a1b + 0d5ea5c commit a3d1d13

File tree

4 files changed

+56
-20
lines changed

4 files changed

+56
-20
lines changed

.travis.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
dist: focal
22
language: python
33

4+
branches:
5+
only:
6+
- main
7+
48
python:
9+
- '3.9'
510
- '3.12'
611

7-
cache:
8-
directories:
9-
- $TRAVIS_BUILD_DIR/src/
10-
branch:
11-
- master
12+
services:
13+
- docker
1214

1315
addons:
1416
apt:
@@ -22,9 +24,41 @@ before_install:
2224
install:
2325
- pip install .[tests]
2426

27+
cache:
28+
directories:
29+
- $TRAVIS_BUILD_DIR/src/
30+
2531
before_script:
2632
- python3 install_genome.py $TRAVIS_BUILD_DIR/src/
2733

2834
script:
2935
- pytest tests
3036
- python3 test.py
37+
38+
after_success:
39+
- |
40+
if [ "$TRAVIS_BRANCH" == "main" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PYTHON_VERSION" == "3.12" ]; then
41+
echo "Starting Docker deployment to GHCR for alexandrovlab..."
42+
43+
VERSION_TAG=$(grep "VERSION = " setup.py | cut -d'"' -f2)
44+
45+
# Get the repository name and convert it to lowercase
46+
REPO_NAME=$(basename $TRAVIS_REPO_SLUG | tr '[:upper:]' '[:lower:]')
47+
IMAGE_NAME="ghcr.io/alexandrovlab/$REPO_NAME"
48+
49+
echo "Building version: $VERSION_TAG for image: $IMAGE_NAME"
50+
51+
echo "$GHCR_PASSWORD" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
52+
53+
docker build \
54+
--build-arg COMMIT_SHA=$TRAVIS_COMMIT \
55+
-t $IMAGE_NAME:$VERSION_TAG \
56+
-t $IMAGE_NAME:latest .
57+
58+
docker push $IMAGE_NAME:$VERSION_TAG
59+
docker push $IMAGE_NAME:latest
60+
61+
echo "Docker deployment to GHCR successful"
62+
else
63+
echo "Skipping Docker deployment"
64+
fi

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [1.0.2] - 2025-10-28
10+
11+
### Added
12+
- Implemented a CI/CD pipeline with Travis CI to automate the building and publishing of Docker images to Docker Hub.
13+
914
## [1.0.1] - 2025-10-20
1015

1116
### Fixed

Dockerfile

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@ FROM ubuntu:22.04
44
# Avoid prompts from apt
55
ARG DEBIAN_FRONTEND=noninteractive
66

7-
# Install Python and other dependencies, and apply updates
7+
# Install Python, git, and other dependencies, and apply updates
88
RUN apt-get update && apt-get upgrade -y && \
99
apt-get install -y python3-pip python3-dev git && \
1010
apt-get clean && rm -rf /var/lib/apt/lists/*
1111

12+
# Argument to specify the commit, defaults to the 'main' branch
13+
ARG COMMIT_SHA=main
14+
1215
# Set the working directory in the container
1316
WORKDIR /usr/src/app
1417

15-
# Clone the specific branch of the repository
16-
RUN git clone https://github.com/AlexandrovLab/SigProfilerAssignment.git .
17-
18-
# Install the dependencies from the requirements.txt in the cloned repository
19-
RUN pip3 install --no-cache-dir -r requirements.txt
20-
21-
# Install the SigProfilerAssignment package from PyPI
22-
RUN pip3 install SigProfilerAssignment==0.1.8
18+
# Install the package directly from the specific commit on GitHub
19+
RUN pip3 install 'git+https://github.com/AlexandrovLab/SigProfilerAssignment.git@'${COMMIT_SHA}
2320

24-
# Create a non-root user named 'spm_user'
21+
# Create a non-root user
2522
RUN useradd -m -s /bin/bash spm_user
2623

27-
# Change the ownership of the /usr/src/app directory and its contents to the new non-root user
24+
# Change the ownership of the working directory
2825
RUN chown -R spm_user:spm_user /usr/src/app
2926

30-
# Switch to the non-root user for subsequent commands and when running the container
31-
USER spm_user
27+
# Switch to the non-root user for security
28+
USER spm_user

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if os.path.exists("dist"):
77
shutil.rmtree("dist")
88

9-
VERSION = "1.0.1"
9+
VERSION = "1.0.2"
1010

1111

1212
def write_version_py(filename="SigProfilerAssignment/version.py"):
@@ -15,7 +15,7 @@ def write_version_py(filename="SigProfilerAssignment/version.py"):
1515
# THIS FILE IS GENERATED FROM SigProfilerAssignment SETUP.PY
1616
short_version = '%(version)s'
1717
version = '%(version)s'
18-
Update = 'v1.0.1: Refine CPU parameter logic to pass directly instead of via devopts'
18+
Update = 'v1.0.2: Add automated Docker build and publish pipeline'
1919
2020
"""
2121
fh = open(filename, "w")

0 commit comments

Comments
 (0)