Skip to content

Commit

Permalink
Allow passing envvar into build process to build base image for a spe… (
Browse files Browse the repository at this point in the history
#5)

* Allow passing envvar into build process to build base image for a specific python version

* Add 3.11 build to readme

* Remove now duplicated platform flag

---------

Co-authored-by: Gordon Hart <gordon.hart2@gmail.com>
  • Loading branch information
munkyshi and gordonhart authored Apr 12, 2023
1 parent e2026a0 commit d658a08
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.9-slim AS sqitch-build
ARG PY_VERSION
FROM python:${PY_VERSION}-slim AS sqitch-build

# Install system dependencies.
WORKDIR /work
Expand Down Expand Up @@ -31,7 +32,7 @@ RUN perl Build.PL --quiet --install_base /app --etcdir /etc/sqitch \

################################################################################
# Copy to the final image without all the build stuff.
FROM python:3.9-slim AS sqitch
FROM python:${PY_VERSION}-slim AS sqitch

# Install runtime system dependencies and remove unnecesary files.
RUN mkdir -p /usr/share/man/man1 /usr/share/man/man7 \
Expand All @@ -56,7 +57,8 @@ RUN mkdir -p /usr/share/man/man1 /usr/share/man/man7 \
&& useradd -r -g sqitch --uid=1024 -d /home sqitch \
&& chown -R sqitch:sqitch /home

RUN apt-get update && apt-get install -y python3-pip
RUN apt-get update && apt-get install -y python3-pip curl git-lfs
RUN pip install poetry==1.2.2

# Copy the app and config from the build image.
COPY --from=sqitch-build /app .
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ Kolena
Steps for building Kolena sqitch images:

```sh
./build
docker tag sqitch/sqitch:1.1.0 ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0
docker push ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0
env DIR=snowflake ./build --build-arg sf_account=ara65239
docker tag sqitch/sqitch:1.1.0-snowflake ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0-snowflake
docker push ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0-snowflake
for py_version in 3.7 3.8 3.9 3.10 3.11
do
env PY_VERSION=${py_version} ./build --build-arg sf_account=kolena-eng
docker push ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0-py${py_version}
env DIR=snowflake PY_VERSION=${py_version} ./build --build-arg sf_account=kolena-eng
docker push ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0-snowflake-py${py_version}
done
```

Synopsis
Expand Down
14 changes: 6 additions & 8 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ NAME=sqitch
VERSION=1.3.1

DIR=${DIR:=.}
REGISTRY=${REGISTRY:="$NAME"}
PY_VERSION=${PY_VERSION:="3.9"}
REGISTRY=${REGISTRY:="ghcr.io/kolenaio/docker-sqitch"}
GIT_BRANCH=${GIT_BRANCH:-${TRAVIS_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}}

# For main Sqitch build, the main tag is "latest" and there
# is no sub-package.
Expand All @@ -26,13 +28,8 @@ tagopt=(
--tag "${REGISTRY}/${NAME}:${VERSION}${PKG}"
)

# Include the git tag if differnt from the version.
if [ "$GITHUB_REF_TYPE" == "tag" ]; then
GIT_TAG=${GITHUB_REF/refs\/tags\//}
if [ "$GIT_TAG" != "$VERSION" ]; then
tagopt+=(--tag "${REGISTRY}/${NAME}:${GIT_TAG}${PKG}")
fi
fi
# Always include the version tag.
tagopt+=(--tag "${REGISTRY}/${NAME}:${VERSION}${PKG}-py${PY_VERSION}")

# The Oracle and Snowflake images require amd64.
docker buildx build --platform=linux/amd64 --pull \
Expand All @@ -50,4 +47,5 @@ docker buildx build --platform=linux/amd64 --pull \
--label org.opencontainers.image.description="Sensible database change management" \
"${tagopt[@]}" \
--build-arg "VERSION=${VERSION}" \
--build-arg "PY_VERSION=${PY_VERSION}" \
"$@" .
6 changes: 4 additions & 2 deletions snowflake/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.9-slim AS snow-build
ARG VERSION
ARG PY_VERSION
FROM python:${PY_VERSION}-slim AS snow-build

WORKDIR /work

Expand Down Expand Up @@ -36,7 +38,7 @@ RUN apt-get -qq update \
&& ./snowsql -Uv \
&& echo "[connections]\naccountname = $sf_account\n\n[options]\nnoup = true" > /var/snowsql/.snowsql/config

FROM ghcr.io/kolenaio/docker-sqitch/sqitch:1.1.0
FROM ghcr.io/kolenaio/docker-sqitch/sqitch:${VERSION}-py${PY_VERSION}

# Install runtime dependencies, remove unnecesary files, and create log dir.
USER root
Expand Down

0 comments on commit d658a08

Please sign in to comment.