Skip to content

Commit

Permalink
Docker push by digest
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed May 15, 2024
1 parent fa41870 commit bf45062
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 63 deletions.
84 changes: 74 additions & 10 deletions .github/workflows/docker-image-build-python.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
---
name: Build Python Deps Image

on:
release:
types:
- "released"
types:
- "released"

push:
branches:
- "main"
- "*-rc"

env:
REGISTRY_IMAGE: onaio/python-deps
VERSION: 3.10.14

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -21,35 +27,93 @@ jobs:
steps:
- name: Prepare
run: |
echo "VERSION=3.10.14" >> $GITHUB_ENV
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=semver,pattern={{version}},value=${{ env.VERSION }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and push
id: docker-build
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./python/3.10-deps/Dockerfile
platforms: ${{ matrix.platform }}
cache-from: type=registry,ref=onaio/python-deps:${{ env.VERSION }}
cache-to: type=inline
push: true
provenance: false
outputs: type=image,name=onaio/python-deps:${{ env.VERSION }},push-by-digest=false,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: (Ubuntu) Image digest
run: echo ${{ steps.docker-build-ubuntu.outputs.digest }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=semver,pattern={{version}},value=${{ env.VERSION }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
106 changes: 53 additions & 53 deletions python/3.10-deps/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,58 +10,58 @@ ENV LC_CTYPE en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en

# Install prerequisite packages
RUN apt-get update -q && \
apt-get install -y --no-install-recommends \
automake \
binutils \
build-essential \
curl \
gcc \
gdal-bin \
gfortran \
ghostscript \
git \
libatlas-base-dev \
libbz2-dev \
libffi-dev \
libjpeg-dev \
libmemcached-dev \
libpcre3 \
libpcre3-dev \
libpq-dev \
libproj-dev \
libreadline-dev \
libssl-dev \
libtool \
libxml2-dev \
libxslt1-dev \
locales \
memcached \
netcat-traditional \
openssh-client \
pkg-config \
software-properties-common \
zlib1g-dev \
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
&& locale-gen en_US.UTF-8 \
&& dpkg-reconfigure locales && useradd -G tty -m appuser \
# Fix CVE-2022-40897, CVE-2023-50782, CVE-2024-26130, CVE-2023-0286
&& /usr/local/bin/python3.10 -m pip install --upgrade setuptools pip cryptography \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Generate and set en_US.UTF-8 locale
RUN
USER appuser

RUN curl https://pyenv.run | bash

ENV HOME /home/appuser
ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH $PYENV_ROOT/versions/3.10.14/bin:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

RUN pyenv install 3.10.14 && pyenv global 3.10.14 && pyenv rehash
# # Install prerequisite packages
# RUN apt-get update -q && \
# apt-get install -y --no-install-recommends \
# automake \
# binutils \
# build-essential \
# curl \
# gcc \
# gdal-bin \
# gfortran \
# ghostscript \
# git \
# libatlas-base-dev \
# libbz2-dev \
# libffi-dev \
# libjpeg-dev \
# libmemcached-dev \
# libpcre3 \
# libpcre3-dev \
# libpq-dev \
# libproj-dev \
# libreadline-dev \
# libssl-dev \
# libtool \
# libxml2-dev \
# libxslt1-dev \
# locales \
# memcached \
# netcat-traditional \
# openssh-client \
# pkg-config \
# software-properties-common \
# zlib1g-dev \
# && sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
# && locale-gen en_US.UTF-8 \
# && dpkg-reconfigure locales && useradd -G tty -m appuser \
# # Fix CVE-2022-40897, CVE-2023-50782, CVE-2024-26130, CVE-2023-0286
# && /usr/local/bin/python3.10 -m pip install --upgrade setuptools pip cryptography \
# && apt-get autoremove -y \
# && apt-get clean -y \
# && rm -rf /var/lib/apt/lists/*
#
# # Generate and set en_US.UTF-8 locale
# RUN
# USER appuser
#
# RUN curl https://pyenv.run | bash
#
# ENV HOME /home/appuser
# ENV PYENV_ROOT="$HOME/.pyenv"
# ENV PATH $PYENV_ROOT/versions/3.10.14/bin:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
#
# RUN pyenv install 3.10.14 && pyenv global 3.10.14 && pyenv rehash

CMD ["python"]

0 comments on commit bf45062

Please sign in to comment.