feat(build): enable cross platform build

!3
This commit is contained in:
2023-05-08 12:12:10 +09:30
parent 0a367146bf
commit 32ae824447
2 changed files with 96 additions and 33 deletions

View File

@ -2,17 +2,20 @@
variables:
GIT_SUBMODULE_STRATEGY: recursive
MY_PROJECT_ID: "45741845"
DOCKER_TARGET_PLATFORMS: linux/amd64,linux/arm64
stages:
- validation
- build
- validation
#- build
- prepare
- test
- release
- sync
- publish
include:
- project: nofusscomputing/projects/gitlab-ci
ref: 36ce0b0b76e6769c7a2e0d4ea0f3fcd2cc2d6bb1
@ -21,39 +24,65 @@ include:
- gitlab_release/.gitlab-ci.yml
- git_push_mirror/.gitlab-ci.yml
# docker:23
# docker pull docker/buildx-bin:0.10.4
Docker Container:
stage: build
image: docker:latest
image: registry.gitlab.com/gdunstone/docker-buildx-qemu
services:
- docker:19.03.12-dind
#- docker:latest-dind
#- docker:19.03.12-dind
- name: docker:23-dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
# See https://github.com/docker-library/docker/pull/166
DOCKER_TLS_CERTDIR: ""
IMAGE_NAME: ansible-ee
# DOCKER_TARGET_PLATFORMS: linux/amd64,linux/arm64
before_script:
- docker info
# - docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- apk update
- apk add --update --no-cache python3 git && ln -sf python3 /usr/bin/python
- python3 -m ensurepip
# - apk update
# - apk add --update --no-cache python3 git && ln -sf python3 /usr/bin/python
- export DEBIAN_FRONTEND=noninteractive
- apt update --allow-releaseinfo-change
- apt --no-install-recommends -yq install python3 git python3-pip
#- python3 -m ensurepip
#- pip3 install -r gitlab-ci/gitlab_release/requirements.txt
- pip3 install setuptools wheel
- pip3 install commitizen==2.21.0 # version specified so current build works.
- pip3 install gitlab-ci/gitlab_release/python-module/cz_nfc/.
#- docker buildx create --use
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
- docker buildx create --driver=docker-container --driver-opt image=moby/buildkit:v0.11.6 --use
- docker buildx inspect --bootstrap
# --cache-to=type=registry,ref=$CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA \
script: |
docker build . \
docker buildx build --platform=$DOCKER_TARGET_PLATFORMS . \
--label org.opencontainers.image.created="$(date '+%Y-%m-%d %H:%M:%S%:z')" \
--label org.opencontainers.image.documentation="$CI_PROJECT_URL" \
--label org.opencontainers.image.source="$CI_PROJECT_URL" \
--label org.opencontainers.image.url="$CI_PROJECT_URL/-/releases/$(cz -n cz_nfc version --project)" \
--label org.opencontainers.image.version="$(cz -n cz_nfc version --project)" \
--label org.opencontainers.image.revision="$CI_COMMIT_SHA" \
--no-cache \
--push \
--tag $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
docker image inspect $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
for i in ${DOCKER_TARGET_PLATFORMS//,/ }
do
# call your procedure/other scripts here below
docker pull --platform $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
docker push $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
docker image inspect $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
done
#allow_failure: true
rules:
@ -65,24 +94,33 @@ Docker Container:
# when: on_success
- if: '$CI_COMMIT_BRANCH != "master"'
allow_failure: true
when: manual
#when: manual
when: always
- when: never
Docker Hub:
stage: publish
image: docker:latest
image: docker:23
services:
- docker:19.03.12-dind
#- docker:latest-dind
#- docker:19.03.12-dind
- docker:23-dind
variables:
IMAGE_NAME: ansible-ee
before_script:
- export
- docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker pull $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA
- docker logout $CI_REGISTRY
- |
docker login $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
for i in ${DOCKER_TARGET_PLATFORMS//,/ }
do
docker pull --platform $i $CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_SHA;
done
docker logout $CI_REGISTRY
script:
# - Release_TAG=$(cat $CI_PROJECT_DIR/dist/version)
- docker login docker.io -u $NFC_DOCKERHUB_USERNAME -p $NFC_DOCKERHUB_TOKEN
@ -90,7 +128,9 @@ Docker Hub:
- echo Branch tag is $Branch_TAG
- docker image ls
- |
DH_LATEST_TAG=dev
if [ "0$CI_COMMIT_BRANCH" == "0development" ]; then

View File

@ -1,11 +1,15 @@
# docker pull python:3.9.16-slim-bullseye
# docker pull python:3.10.11-slim-bullseye
FROM python:3.9.16-slim-bullseye as scratchpad
# docker pull python:3.10-slim-bullseye
# docker pull python:3.11-slim-bullseye
# docker pull python:3.11-bullseye
FROM --platform=$BUILDPLATFORM python:3.11-bullseye as scratchpad
RUN apt update && \
apt install --no-install-recommends -y \
RUN export DEBIAN_FRONTEND=noninteractive \
&& dpkg-reconfigure debconf -f noninteractive \
&& apt update \
&& apt install --reinstall --no-install-recommends -yq \
git
@ -13,7 +17,11 @@ RUN git clone -b development --depth 1 https://gitlab.com/nofusscomputing/projec
FROM python:3.9.16-slim-bullseye
FROM --platform=$TARGETPLATFORM python:3.11-bullseye
# Ansible chucks a wobbler without. see: https://github.com/ansible/ansible/issues/78283
ENV LC_ALL en_US.UTF-8
COPY --from=scratchpad /tmp/ansible-roles/roles /etc/ansible/roles
@ -32,14 +40,28 @@ LABEL \
# org.opencontainers.image.version="{git tag}"
RUN apt update && \
apt install --no-install-recommends -y \
# This Black Magic exists as libc-bin was being a turd and returning errors when trying to install git, ssh.
# see: https://askubuntu.com/questions/1339558/cant-build-dockerfile-for-arm64-due-to-libc-bin-segmentation-fault
# see: https://github.com/dcycle/prepare-docker-buildx/blob/09057fe4879e31ee780b9e69b87f41327ca8cd8e/example/Dockerfile#L8-L10
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt update \
&& apt --fix-broken install \
&& apt install -y libc-bin locales-all \
&& apt update \
&& apt install --reinstall --no-install-recommends -yq \
openssh-client \
git || true \
&& dpkg --purge --force-all libc-bin \
&& apt-get install --no-install-recommends -y \
openssh-client \
git \
ssh && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /etc/ansible/roles && \
mkdir -p /etc/ansible/collections && \
mkdir -p /workdir
# End of Black Magic
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /etc/ansible/roles \
&& mkdir -p /etc/ansible/collections \
&& mkdir -p /workdir
WORKDIR /workdir
@ -48,8 +70,9 @@ COPY ansible.cfg /etc/ansible/ansible.cfg
RUN pip install --upgrade pip \
&& pip install \
ansible \
ansible-lint
ansible-core==2.14.5 \
ansible-lint==6.15.0
RUN ansible-galaxy collection install \
awx.awx \