Skip to content

Commit

Permalink
Use a different alpine linux version per ansible version (#3)
Browse files Browse the repository at this point in the history
* WIP

* Update build.sh to be a bit more dumb, just try building all the variations

* Only bother removing externally-managed files if we got some resutls

* Allow building on PR for now

* Fix alpine versions

* Quote versions so they don’t get truncated weirdly

* Refactor build script

* Remove current PR from actions
  • Loading branch information
tomb1n0 authored Jul 16, 2024
1 parent bc5e536 commit c1a3329
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
image:
- 2.10.0
- 3.4.0
- 4.8.0
- 4.10.0
- 5.5.0
- 5.8.0
- 5.10.0
- 6.7.0
- 7.7.0
- 8.7.0
- 9.7.0
- 10.1.0
versions:
- { ansible: "2.10.0", alpine: "3.13" }
- { ansible: "3.4.0", alpine: "3.15" }
- { ansible: "4.8.0", alpine: "3.15" }
- { ansible: "4.10.0", alpine: "3.15" }
- { ansible: "5.5.0", alpine: "3.16" }
- { ansible: "5.8.0", alpine: "3.16" }
- { ansible: "5.10.0", alpine: "3.16" }
- { ansible: "6.7.0", alpine: "3.16" }
- { ansible: "7.7.0", alpine: "3.18" }
- { ansible: "8.7.0", alpine: "3.18" }
- { ansible: "9.7.0", alpine: "3.20" }
- { ansible: "10.1.0", alpine: "3.20" }
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -40,7 +40,8 @@ jobs:
uses: docker/build-push-action@v2
with:
build-args: |
ANSIBLE_VERSION=${{ matrix.image }}
ANSIBLE_VERSION=${{ matrix.versions.ansible }}
BASE_IMAGE=alpine:${{ matrix.versions.alpine }}
platforms: linux/amd64, linux/arm64
push: true
tags: rareloop/ansible:${{ matrix.image }}
tags: rareloop/ansible:${{ matrix.versions.ansible }}
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
FROM alpine:latest
ARG BASE_IMAGE=alpine:3.15

FROM $BASE_IMAGE

# Use Ansible 4.8.0 by default
ARG ANSIBLE_VERSION=4.8.0
ENV ENV_ANSIBLE_VERSION=$ANSIBLE_VERSION

# Installs Dependencies
RUN apk add --update python3 py-pip openssl ca-certificates bash git sudo zip sshpass openssh-client rsync \
&& apk add --update --virtual build-dependencies python3-dev libffi-dev openssl-dev build-base

# Note: Apply fix from Jeff that allows pip install to work without --break-system-packages
# https://www.jeffgeerling.com/blog/2023/how-solve-error-externally-managed-environment-when-installing-pip3
RUN apk add --update python3 py-pip openssl ca-certificates bash git sudo zip \
&& apk add --update --virtual build-dependencies python3-dev libffi-dev openssl-dev build-base \
&& find /usr/lib/python* | grep EXTERNALLY-MANAGED | xargs rm \
&& pip install --upgrade pip cffi \
&& pip install --upgrade pycrypto pywinrm \
&& apk add --update sshpass openssh-client rsync
RUN find /usr/lib/python* | grep EXTERNALLY-MANAGED | xargs -r rm

# Pip Dependencies
RUN pip install --upgrade pip cffi \
&& pip install --upgrade pycrypto pywinrm

# Install Ansible
RUN pip install ansible==$ENV_ANSIBLE_VERSION
Expand Down
33 changes: 26 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
#!/bin/bash
# You can get an idea for which alpine version you need by looking here:
# https://pkgs.alpinelinux.org/packages?name=python3&branch=v3.15&repo=&arch=&maintainer=
#
# You can check what Python3 version is available for which Alpine Linux version and adjust accordingly.
#
# You should check https://endoflife.date/ansible to consider which Python version is suitable.

ANSIBLE_VERSION=4.8.0
# Using two parallel arrays to match up an ansible version to its base alpine image
# MacOS doesn't come with a high enough bash version to use bash associative arrays.
ANSIBLE_VERSIONS=("2.10.0" "3.4.0" "4.8.0" "4.10.0" "5.5.0" "5.8.0" "5.10.0" "6.7.0" "7.7.0" "8.7.0" "9.7.0" "10.1.0")
BASE_IMAGES=("alpine:3.13" "alpine:3.15" "alpine:3.15" "alpine:3.15" "alpine:3.16" "alpine:3.16" "alpine:3.16" "alpine:3.16" "alpine:3.18" "alpine:3.18" "alpine:3.20" "alpine:3.20")

if [ -n "$1" ]; then
ANSIBLE_VERSION=$1;
shift 1
fi
LENGTH=${#ANSIBLE_VERSIONS[@]}

# Ansible 4.8.0
(docker build --build-arg ANSIBLE_VERSION=${ANSIBLE_VERSION} . -t rareloop/ansible:${ANSIBLE_VERSION} && docker push rareloop/ansible:${ANSIBLE_VERSION})
for (( i=0; i<${LENGTH}; i++ )); do
ANSIBLE_VERSION=${ANSIBLE_VERSIONS[$i]}
BASE_IMAGE=${BASE_IMAGES[$i]}

echo "=====================";
echo "Ansible Version: ${ANSIBLE_VERSION}";
echo "Base Image: ${BASE_IMAGE}";
echo "=====================";

docker build --build-arg ANSIBLE_VERSION="${ANSIBLE_VERSION}" --build-arg BASE_IMAGE="${BASE_IMAGE}" . -t rareloop-local/ansible:"${ANSIBLE_VERSION}"
docker run -it --rm rareloop-local/ansible:"${ANSIBLE_VERSION}" ansible --version

echo "";
echo "";
echo "";
done

0 comments on commit c1a3329

Please sign in to comment.