Skip to content

Commit

Permalink
Migrate from DockerHub registry to GitHub registry (#212)
Browse files Browse the repository at this point in the history
Description of changes:
-  no longer push images to the DockerHub [espressomd](https://hub.docker.com/u/espressomd) organization
- generate a more compact Debian image without Stokesian Dynamics dependencies to reduce pull times
- generate images suitable for GitHub Actions (without a USER layer) with a special tag
   - generating alternative versions that work out-of-the-box for Docker users (helps with debugging)
  • Loading branch information
jngrad authored Apr 6, 2023
2 parents 4dffd53 + f55dcbf commit f6cf740
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
9 changes: 0 additions & 9 deletions .github/actions/docker/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# action.yml
name: 'docker'
description: 'Build and deploy docker images'
inputs:
Expand All @@ -17,12 +16,6 @@ inputs:
tag:
description: 'Tag for the image'
required: true
dockerhub_user:
description: 'Username on dockerhub for second deploy'
required: false
dockerhub_password:
description: 'Password for dockerhub registry.'
required: false
build_args:
description: 'List of build arguments.'
required: false
Expand All @@ -35,6 +28,4 @@ runs:
- ${{ inputs.password }}
- ${{ inputs.event_name }}
- ${{ inputs.tag }}
- ${{ inputs.dockerhub_user }}
- ${{ inputs.dockerhub_password }}
- ${{ inputs.build_args }}
27 changes: 16 additions & 11 deletions .github/actions/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,30 @@ project=$(echo "$2" | cut -d'/' -f2)
password=$3
event_name=$4
tag=$5
dockerhub_user=$6
dockerhub_password=$7

echo "Log in to registry."
echo "${password}" | docker login -u "${username}" --password-stdin docker.pkg.github.com || exit 1

full_tag="docker.pkg.github.com/${username}/${project}/${image}:${tag}"
dockerfile="docker/Dockerfile-${image}"
full_tag_github_action=""
if grep -q "FROM image_base AS image_standalone" "${dockerfile}"; then
full_tag_github_action="${full_tag}-base-layer"
fi

echo "Building image with tag: ${full_tag}"
docker build docker -t "${full_tag}" -f "docker/Dockerfile-${image}" || exit 1
docker build docker -t "${full_tag}" -f "${dockerfile}" || exit 1
if [ ! -z "${full_tag_github_action}" ]; then
echo "Building GitHub Action-specific image with tag: ${full_tag_github_action}"
docker build docker -t "${full_tag_github_action}" -f "${dockerfile}" --target image_base || exit 1
fi

if [ "${event_name}" != "pull_request" ]; then
if [ "${event_name}" = "pull_request" ]; then
echo "Pull request: not pushing to registry."
else
echo "Pushing to registry."
docker push "${full_tag}" || exit 1
if [ "${dockerhub_user}" != "" ]; then
echo "${dockerhub_password}" | docker login -u "${dockerhub_user}" --password-stdin || exit 1
docker tag "${full_tag}" "${username}/${project}-${image}:${tag}"
docker push "${username}/${project}-${image}:${tag}" || exit 1
fi
else
echo "Pull request: not pushing to registry."
if [ ! -z "${full_tag_github_action}" ]; then
docker push "${full_tag_github_action}" || exit 1
fi
fi
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
event_name: ${{ github.event_name }}
tag: ${{ github.sha }}
dockerhub_user: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_password: ${{ secrets.DOCKERHUB_TOKEN }}
14 changes: 7 additions & 7 deletions docker/Dockerfile-debian
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
FROM debian:bullseye
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install -y --no-install-recommends \
FROM debian:bullseye AS image_base
RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
apt-utils \
build-essential \
curl \
ccache \
cmake \
cython3 \
gdb \
git \
libblas-dev \
libboost-dev libboost-serialization-dev libboost-mpi-dev libboost-filesystem-dev libboost-test-dev \
libfftw3-dev \
libhdf5-openmpi-dev \
liblapack-dev \
libpython3-dev \
openmpi-bin \
python3 \
Expand All @@ -25,9 +22,12 @@ RUN apt-get update && \
python3-setuptools \
python3-vtk9 \
vim && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --target-release bullseye-backports \
cmake && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

FROM image_base AS image_standalone
RUN useradd -m espresso
USER espresso
WORKDIR /home/espresso
3 changes: 1 addition & 2 deletions docker/Dockerfile-ubuntu-22.04
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM ubuntu:jammy
ENV DEBIAN_FRONTEND noninteractive
COPY install-pfft.sh /tmp
COPY install-scafacos.sh /tmp
RUN apt-get update && \
apt-get install --no-install-recommends -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
apt-utils \
autoconf \
automake \
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile-ubuntu-wo-dependencies
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM ubuntu:jammy
ENV DEBIAN_FRONTEND noninteractive
FROM ubuntu:jammy AS image_base
RUN apt-get update && \
apt-get install --no-install-recommends -y \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
apt-utils \
build-essential \
curl \
Expand All @@ -28,6 +27,7 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

FROM image_base AS image_standalone
RUN useradd -m espresso
USER espresso
WORKDIR /home/espresso

0 comments on commit f6cf740

Please sign in to comment.