Merge pull request #363 from linuxserver/universal-docker-v2

switch to compose v2
This commit is contained in:
aptalca 2022-04-08 14:47:20 -04:00 committed by GitHub
commit fd22798c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 105 additions and 47 deletions

View File

@ -16,25 +16,25 @@ 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
COMBINED_VERSION=${DOCKER_RELEASE}-${COMPOSE_RELEASE}
echo "**** Combined version is ${COMBINED_VERSION} ****"
echo "COMBINED_VERSION=${COMBINED_VERSION}" >> $GITHUB_ENV
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
# Build image
docker build --no-cache --build-arg COMPOSE_TAG=${COMPOSE_TAG} --build-arg COMPOSE_ALPINE_TAG=${COMPOSE_ALPINE_TAG} -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.COMPOSE_VERSION }}
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ 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.COMPOSE_VERSION }}
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ 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
@ -59,8 +59,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.COMPOSE_VERSION }}
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ 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}
@ -72,7 +72,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.COMPOSE_VERSION }}
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ 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}

View File

@ -1,27 +1,89 @@
ARG COMPOSE_TAG="latest"
ARG COMPOSE_ALPINE_TAG="alpine"
FROM ghcr.io/linuxserver/baseimage-alpine:3.15 as buildstage
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
ARG DOCKER_RELEASE
ARG COMPOSE_RELEASE
FROM ghcr.io/linuxserver/baseimage-alpine:3.12 as buildstage
RUN \
echo "**** install packages ****" && \
apk add --no-cache \
curl \
git \
go && \
echo "**** retrieve latest docker version ****" && \
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 && \
echo "**** grab docker ****" && \
mkdir -p \
/root-layer/docker-bins \
/tmp/docker_x86_64 \
/tmp/docker_armv7l \
/tmp/docker_aarch64 && \
curl -fo \
/tmp/docker_x86_64.tgz -L \
"https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_RELEASE}.tgz" && \
tar xf \
/tmp/docker_x86_64.tgz -C \
/tmp/docker_x86_64 --strip-components=1 && \
cp /tmp/docker_x86_64/docker /root-layer/docker-bins/docker_x86_64 && \
curl -fo \
/tmp/docker_armv7l.tgz -L \
"https://download.docker.com/linux/static/stable/armhf/docker-${DOCKER_RELEASE}.tgz" && \
tar xf \
/tmp/docker_armv7l.tgz -C \
/tmp/docker_armv7l --strip-components=1 && \
cp /tmp/docker_armv7l/docker /root-layer/docker-bins/docker_armv7l && \
curl -fo \
/tmp/docker_aarch64.tgz -L \
"https://download.docker.com/linux/static/stable/aarch64/docker-${DOCKER_RELEASE}.tgz" && \
tar xf \
/tmp/docker_aarch64.tgz -C \
/tmp/docker_aarch64 --strip-components=1 && \
cp /tmp/docker_aarch64/docker /root-layer/docker-bins/docker_aarch64 && \
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-bins/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-bins/docker-compose_armv7l -L \
"https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-armv7" && \
curl -fo \
/root-layer/docker-bins/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-bins/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-bins/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-bins/compose-switch_armv7l ./main.go && \
chmod +x /root-layer/docker-bins/* && \
rm -rf /tmp/*
COPY --from=compose-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_x86_64
COPY --from=compose-amd64 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_x86_64
COPY --from=compose-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_armv7l
COPY --from=compose-arm32 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_armv7l
COPY --from=compose-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_aarch64
COPY --from=compose-arm64 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_aarch64
COPY --from=compose-alpine-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_x86_64
COPY --from=compose-alpine-amd64 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_x86_64
COPY --from=compose-alpine-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_armv7l
COPY --from=compose-alpine-arm32 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_armv7l
COPY --from=compose-alpine-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_aarch64
COPY --from=compose-alpine-arm64 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_aarch64
COPY root/ /root-layer/
# runtime stage

View File

@ -1,18 +1,14 @@
#!/usr/bin/with-contenv bash
echo "**** installing docker and docker compose ****"
if [ -f /usr/bin/apt ]; then
DISTRONAME="ubuntu"
else
DISTRONAME="alpine"
fi
ARCH=$(uname -m)
if [ -f "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" ] ; then
if [ -d "/docker-bins" ] ; then
echo "Copying over docker and docker-compose binaries"
mv "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" /usr/local/bin/docker-compose
mv "/docker-compose-${DISTRONAME}/docker_${ARCH}" /usr/local/bin/docker
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-bins/docker-compose_${ARCH}" /usr/local/lib/docker/cli-plugins/docker-compose
mv "/docker-bins/docker_${ARCH}" /usr/local/bin/docker
mv "/docker-bins/compose-switch_${ARCH}" /usr/local/bin/docker-compose
rm -rf /docker-bins
else
echo "**** docker and docker-compose already installed, skipping ****"
fi
@ -30,7 +26,7 @@ if [ -S /var/run/docker.sock ]; then
usermod -aG "${DOCKER_NAME}" abc
fi
elif [ -n "$DOCKER_HOST" ]; then
echo "**** /var/run/docker.sock is not mapped, therefore, docker client will only work with a remote docker service ****"
echo "**** Remote docker service $DOCKER_HOST will be used ****"
else
echo "**** Please map /var/run/docker.sock for access to docker service on host. Alternatively you can manually define a remote host address with the docker cli option -H ****"
fi