From c53621e890bb0091d87397089e606ec68f78b957 Mon Sep 17 00:00:00 2001 From: aptalca Date: Fri, 8 Apr 2022 12:46:04 -0400 Subject: [PATCH] switch to compose v2 --- .github/workflows/BuildImage.yml | 29 +++++----- Dockerfile | 67 +++++++++++++++++------- root/etc/cont-init.d/98-docker-in-docker | 10 ++-- 3 files changed, 65 insertions(+), 41 deletions(-) diff --git a/.github/workflows/BuildImage.yml b/.github/workflows/BuildImage.yml index 44b17a9..e5825dc 100644 --- a/.github/workflows/BuildImage.yml +++ b/.github/workflows/BuildImage.yml @@ -16,27 +16,24 @@ jobs: - name: Build image run: | # Set version - if [ -z ${COMPOSE_TAG+x} ]; then COMPOSE_TAG=$(curl -sX GET "https://api.github.com/repos/linuxserver/docker-docker-compose/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]'); fi - if [ -z ${COMPOSE_ALPINE_TAG+x} ]; then COMPOSE_ALPINE_TAG=$(curl -sX GET "https://api.github.com/repos/linuxserver/docker-docker-compose/releases" | jq -r 'first(.[] | select(.prerelease==true)) | .tag_name'); fi - COMPOSE_VERSION=$(echo "$COMPOSE_TAG" | sed 's|-ls.*||g') - echo "COMPOSE_VERSION=${COMPOSE_VERSION}" >> $GITHUB_ENV - COMPOSE_ALPINE_VERSION="$(echo ${COMPOSE_ALPINE_TAG} | sed 's|-ls.*||g' | sed 's|alpine-||g')" - if [ "$COMPOSE_VERSION" != "$COMPOSE_ALPINE_VERSION" ]; then echo "ubuntu and alpine versions are different; exiting!" && exit 1; else echo "ubuntu and alpine versions are the same, continuing with build"; fi + if [ -z ${COMPOSE_RELEASE+x} ]; then COMPOSE_RELEASE=$(curl -sX GET "https://api.github.com/repos/docker/compose/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]' | sed 's|^v||'); fi if [ -z ${DOCKER_RELEASE+x} ]; then DOCKER_RELEASE=$(curl -sX GET "https://api.github.com/repos/moby/moby/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]' | sed 's|^v||'); fi if curl -fSsL "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_RELEASE}.tgz" >/dev/null && curl -fSsL "https://download.docker.com/linux/static/stable/armhf/docker-${DOCKER_RELEASE}.tgz" >/dev/null && curl -fSsL "https://download.docker.com/linux/static/stable/aarch64/docker-${DOCKER_RELEASE}.tgz" >/dev/null; then echo "Docker tarballs exist, proceeding"; else echo "Docker tarballs are missing, exiting!" && exit 1; fi - echo "COMBINED_TAG=${DOCKER_RELEASE}-${COMPOSE_VERSION}" >> $GITHUB_ENV + COMBINED_VERSION=${DOCKER_RELEASE}-${COMPOSE_RELEASE} + echo "**** Combined version is ${COMBINED_VERSION} ****" + echo "COMBINED_VERSION=${COMBINED_VERSION}" >> $GITHUB_ENV # Build image - docker build --no-cache --build-arg COMPOSE_TAG=${COMPOSE_TAG} --build-arg COMPOSE_ALPINE_TAG=${COMPOSE_ALPINE_TAG} --build-arg DOCKER_RELEASE=${DOCKER_RELEASE} -t ${{ github.sha }} . + docker build --no-cache --build-arg COMPOSE_RELEASE=${COMPOSE_RELEASE} --build-arg DOCKER_RELEASE=${DOCKER_RELEASE} -t ${{ github.sha }} . - name: Tag image if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }} run: | docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME} - docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }} - docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }}-${{ github.sha }} + docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }} + docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }} docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME} - docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }} - docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }}-${{ github.sha }} + docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }} + docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }} docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} - name: Credential check if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }} @@ -58,8 +55,8 @@ jobs: - name: Push tags to GitHub Container Registry if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }} run: | - docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }} - docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }}-${{ github.sha }} + docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }} + docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }} docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME} - name: Login to DockerHub @@ -69,7 +66,7 @@ jobs: - name: Push tags to DockerHub if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }} run: | - docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }} - docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_TAG }}-${{ github.sha }} + docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }} + docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }} docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }} docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME} diff --git a/Dockerfile b/Dockerfile index 453c7a2..b1f5d20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,15 @@ ## Buildstage ## +FROM ghcr.io/linuxserver/baseimage-alpine:3.15 as buildstage + ARG DOCKER_RELEASE -ARG COMPOSE_TAG="latest" -ARG COMPOSE_ALPINE_TAG="alpine" - -FROM ghcr.io/linuxserver/docker-compose:amd64-${COMPOSE_TAG} as compose-amd64 -FROM ghcr.io/linuxserver/docker-compose:arm32v7-${COMPOSE_TAG} as compose-arm32 -FROM ghcr.io/linuxserver/docker-compose:arm64v8-${COMPOSE_TAG} as compose-arm64 -FROM ghcr.io/linuxserver/docker-compose:amd64-${COMPOSE_ALPINE_TAG} as compose-alpine-amd64 -FROM ghcr.io/linuxserver/docker-compose:arm32v7-${COMPOSE_ALPINE_TAG} as compose-alpine-arm32 -FROM ghcr.io/linuxserver/docker-compose:arm64v8-${COMPOSE_ALPINE_TAG} as compose-alpine-arm64 - -FROM ghcr.io/linuxserver/baseimage-alpine:3.14 as buildstage +ARG COMPOSE_RELEASE RUN \ echo "**** install packages ****" && \ apk add --no-cache \ - curl && \ + curl \ + git \ + go && \ echo "**** retrieve latest version ****" && \ if [ -z ${DOCKER_RELEASE+x} ]; then \ DOCKER_RELEASE=$(curl -sX GET "https://api.github.com/repos/moby/moby/releases/latest" \ @@ -32,15 +26,50 @@ RUN \ "https://download.docker.com/linux/static/stable/armhf/docker-${DOCKER_RELEASE}.tgz" && \ curl -fo \ /root-layer/docker-tgz/docker_aarch64.tgz -L \ - "https://download.docker.com/linux/static/stable/aarch64/docker-${DOCKER_RELEASE}.tgz" + "https://download.docker.com/linux/static/stable/aarch64/docker-${DOCKER_RELEASE}.tgz" && \ + echo "**** retrieve latest compose version ****" && \ + if [ -z ${COMPOSE_RELEASE+x} ]; then \ + COMPOSE_RELEASE=$(curl -sX GET "https://api.github.com/repos/docker/compose/releases/latest" \ + | awk '/tag_name/{print $4;exit}' FS='[""]' \ + | sed 's|^v||'); \ + fi && \ + echo "**** grab compose ****" && \ + curl -fo \ + /root-layer/docker-tgz/docker-compose_x86_64 -L \ + "https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-x86_64" && \ + curl -fo \ + /root-layer/docker-tgz/docker-compose_armv7l -L \ + "https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-armv7" && \ + curl -fo \ + /root-layer/docker-tgz/docker-compose_aarch64 -L \ + "https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-aarch64" && \ + echo "**** retrieve latest compose switch version ****" && \ + if [ -z ${SWITCH_RELEASE+x} ]; then \ + SWITCH_RELEASE=$(curl -sX GET "https://api.github.com/repos/docker/compose-switch/releases/latest" \ + | awk '/tag_name/{print $4;exit}' FS='[""]' \ + | sed 's|^v||'); \ + fi && \ + echo "**** grab compose switch ****" && \ + curl -fo \ + /root-layer/docker-tgz/compose-switch_x86_64 -L \ + "https://github.com/docker/compose-switch/releases/download/v${SWITCH_RELEASE}/docker-compose-linux-amd64" && \ + curl -fo \ + /root-layer/docker-tgz/compose-switch_aarch64 -L \ + "https://github.com/docker/compose-switch/releases/download/v${SWITCH_RELEASE}/docker-compose-linux-arm64" && \ + echo "**** compile compose switch on armhf ****" && \ + curl -fo \ + /tmp/compose-switch.tar.gz -L \ + "https://github.com/docker/compose-switch/archive/refs/tags/v${SWITCH_RELEASE}.tar.gz" && \ + mkdir -p /tmp/compose-switch && \ + tar xf \ + /tmp/compose-switch.tar.gz -C \ + /tmp/compose-switch --strip-components=1 && \ + cd /tmp/compose-switch && \ + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X github.com/docker/compose-switch/internal.Version=${SWITCH_RELEASE}" -o /root-layer/docker-tgz/compose-switch_armv7l ./main.go && \ + chmod +x /root-layer/docker-tgz/* && \ + rm -rf /tmp/* # copy local files -COPY --from=compose-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_x86_64 -COPY --from=compose-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_armv7l -COPY --from=compose-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_aarch64 -COPY --from=compose-alpine-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_x86_64 -COPY --from=compose-alpine-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_armv7l -COPY --from=compose-alpine-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_aarch64 COPY root/ /root-layer/ ## Single layer deployed image ## diff --git a/root/etc/cont-init.d/98-docker-in-docker b/root/etc/cont-init.d/98-docker-in-docker index 437e58e..e25712b 100644 --- a/root/etc/cont-init.d/98-docker-in-docker +++ b/root/etc/cont-init.d/98-docker-in-docker @@ -6,7 +6,6 @@ chown -R ${ABC_USER}:${ABC_USER} /config/logs echo "**** installing docker and docker compose ****" if [ -f /usr/bin/apt ]; then - DISTRONAME="ubuntu" apt-get install -y \ btrfs-progs \ ca-certificates \ @@ -19,7 +18,6 @@ if [ -f /usr/bin/apt ]; then xfsprogs \ xz-utils else - DISTRONAME="alpine" apk add --no-cache \ btrfs-progs \ curl \ @@ -33,11 +31,11 @@ else xz fi ARCH=$(uname -m) -if [ -f "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" ] ; then +if [ -d "/docker-tgz" ] ; then echo "Copying over docker and docker-compose binaries" - mv "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose - rm -rf /docker-compose-ubuntu /docker-compose-alpine + mkdir -p /usr/local/lib/docker/cli-plugins + mv "/docker-tgz/docker-compose_${ARCH}" /usr/local/lib/docker/cli-plugins/docker-compose + mv "/docker-tgz/compose-switch_${ARCH}" /usr/local/bin/docker-compose tar xf /docker-tgz/docker_${ARCH}.tgz \ --strip-components=1 -C \ /usr/local/bin/