Skip to content

Commit ea31021

Browse files
ddundobtobers
authored andcommitted
Automatically build and push Docker container (#61)
Closes #52. This PR adds a workflow to automatically build and push the PyGEM image to the GitHub Container Registry (ghcr.io), that will then be visible at https://github.com/orgs/PyGEM-Community/packages. It builds it from the Dockerfile that I add as well. It's pushed to ghcr only when the workflow is triggered on the master or dev branches: that is, if it's triggered by schedule or when we merge relevant commits to the branches. But it's always built in PRs so we can check that it builds successfully. Currently the image is quite large (9.1 GB) but can be reduced to about 2.5GB, as described in #60.
1 parent ebddb98 commit ea31021

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

.github/workflows/docker_pygem.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 'Build bespoke PyGEM Docker container'
2+
3+
on:
4+
# Trigger when these files change in an open PR
5+
pull_request:
6+
paths:
7+
- '.github/workflows/docker_pygem.yml'
8+
- 'docker/Dockerfile'
9+
10+
# Trigger when these files change on the master or dev branches
11+
push:
12+
branches:
13+
- master
14+
- dev
15+
paths:
16+
- '.github/workflows/docker_pygem.yml'
17+
- 'docker/Dockerfile'
18+
19+
# Trigger every Saturday at 12AM GMT
20+
schedule:
21+
- cron: '0 0 * * 6'
22+
23+
# Manually trigger the workflow
24+
workflow_dispatch:
25+
26+
# Stop the workflow if a new one is started
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.ref }}
29+
cancel-in-progress: true
30+
31+
permissions:
32+
contents: read
33+
packages: write
34+
35+
jobs:
36+
docker:
37+
name: 'Build and push Docker container'
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- name: 'Check out the repo'
42+
uses: actions/checkout@v4
43+
44+
- name: 'Set up Docker buildx'
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: 'Log into GitHub Container Repository'
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ghcr.io
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
logout: true
54+
55+
- name: 'Build and Push Docker Container'
56+
uses: docker/build-push-action@v5
57+
with:
58+
push: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' }}
59+
no-cache: true
60+
file: 'docker/Dockerfile'
61+
build-args: |
62+
PYGEM_BRANCH=${{ github.ref == 'refs/heads/master' && 'master' || 'dev' }}
63+
tags: |
64+
ghcr.io/pygem-community/pygem:${{ github.ref == 'refs/heads/master' && 'latest' || github.ref == 'refs/heads/dev' && 'dev' }}

docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM ubuntu:latest
2+
3+
# Install system dependencies
4+
RUN apt-get update && apt-get install -y --no-install-recommends \
5+
sudo curl vim git tree python3-pip python3-venv python3-dev build-essential \
6+
&& rm -rf /var/lib/apt/lists/*
7+
8+
# Add non-root user 'ubuntu' to sudo group
9+
RUN usermod -aG sudo ubuntu && \
10+
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu
11+
12+
# Switch to non-root user
13+
USER ubuntu
14+
WORKDIR /home/ubuntu
15+
16+
# Add .local/bin to PATH
17+
ENV PATH="/home/ubuntu/.local/bin:${PATH}"
18+
19+
# What PyGEM branch to clone (either master or dev; see docker_pygem.yml)
20+
ARG PYGEM_BRANCH=master
21+
22+
RUN git clone --branch ${PYGEM_BRANCH} https://github.com/PyGEM-Community/PyGEM.git && \
23+
pip install --break-system-packages -e PyGEM
24+
25+
# Clone the PyGEM notebooks repository, which are used for testing
26+
RUN git clone https://github.com/PyGEM-Community/PyGEM-notebooks.git

0 commit comments

Comments
 (0)