Skip to content

Commit

Permalink
Update Dockerfile and build scripts
Browse files Browse the repository at this point in the history
These changes allow for a multi-architecture build process using `docker buildx`

These changes are suitable for Curator 6.x and 7.x
  • Loading branch information
untergeek committed Feb 8, 2023
1 parent e1e545b commit 8d42290
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
43 changes: 27 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
# syntax=docker/dockerfile:1
FROM python:3.11.1-alpine3.17 as builder
ARG PYVER=3.11.1
ARG ALPTAG=3.17
FROM python:${PYVER}-alpine${ALPTAG} as builder

# Add the community repo for access to patchelf binary package
RUN echo 'https://dl-cdn.alpinelinux.org/alpine/v3.17/community/' >> /etc/apk/repositories
ARG ALPTAG
RUN echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPTAG}/community/" >> /etc/apk/repositories
RUN apk --no-cache upgrade && apk --no-cache add build-base tar musl-utils openssl-dev patchelf
# patchelf-wrapper is necessary now for cx_Freeze, but not for Curator itself.
RUN pip3 install setuptools cx_Freeze patchelf-wrapper

COPY . .
RUN ln -s /lib/libc.musl-x86_64.so.1 ldd
RUN ln -s /lib /lib64
# alpine4docker.sh does some link magic necessary for cx_Freeze execution
# These files are platform dependent because the architecture is in the file name.
# This script handles it, effectively:
# ARCH=$(uname -m)
# ln -s /lib/libc.musl-${ARCH}.so.1 ldd
# ln -s /lib /lib64
RUN /bin/sh alpine4docker.sh

# Install Curator locally
RUN pip3 install .

# Build (or rather Freeze) Curator
RUN python3 setup.py build_exe

# This will add the cacert.pem from certifi to the default location Curator will look
RUN <<eot
#!/usr/bin/env python3
import os
import shutil
import certifi
DEST = 'build/exe.linux-x86_64-3.11'
CERT = certifi.where()
shutil.copy(CERT, DEST)
eot

FROM alpine:3.17
# and also move 'build/exe.{system().lower()}-{machine()}-{MAJOR}.{MINOR}' to curator_build
RUN python3 post4docker.py

### End `builder` segment

### Copy frozen binary to the container that will actually be published
ARG ALPTAG
FROM alpine:${ALPTAG}
RUN apk --no-cache upgrade && apk --no-cache add openssl-dev expat
COPY --from=builder build/exe.linux-x86_64-3.11 /curator/
# The path `curator_build` is from `builder` and `post4docker.py`
COPY --from=builder curator_build /curator/
RUN mkdir /.curator

USER nobody:nobody
Expand Down
4 changes: 4 additions & 0 deletions alpine4docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARCH=$(uname -m)

ln -s /lib/libc.musl-${ARCH}.so.1 ldd
ln -s /lib /lib64
15 changes: 15 additions & 0 deletions post4docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
import shutil
import certifi
from platform import machine, system, python_version
MAJOR, MINOR = tuple(python_version().split('.')[:-1])
SYSTEM = system().lower()
BUILD = f'build/exe.{system().lower()}-{machine()}-{MAJOR}.{MINOR}'
CERT = certifi.where()
TARGET = 'curator_build'

# First copy the cert to BUILD
shutil.copy(CERT, BUILD)

# Then rename the path of BUILD itself
shutil.move(BUILD, TARGET)

0 comments on commit 8d42290

Please sign in to comment.