Skip to content

Commit fd22798

Browse files
authored
Merge pull request #363 from linuxserver/universal-docker-v2
switch to compose v2
2 parents b58c3ed + 67cb6a3 commit fd22798

File tree

3 files changed

+105
-47
lines changed

3 files changed

+105
-47
lines changed

.github/workflows/BuildImage.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ jobs:
1616
- name: Build image
1717
run: |
1818
# Set version
19-
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
20-
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
21-
COMPOSE_VERSION=$(echo "$COMPOSE_TAG" | sed 's|-ls.*||g')
22-
echo "COMPOSE_VERSION=${COMPOSE_VERSION}" >> $GITHUB_ENV
23-
COMPOSE_ALPINE_VERSION="$(echo ${COMPOSE_ALPINE_TAG} | sed 's|-ls.*||g' | sed 's|alpine-||g')"
24-
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
19+
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
20+
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
21+
COMBINED_VERSION=${DOCKER_RELEASE}-${COMPOSE_RELEASE}
22+
echo "**** Combined version is ${COMBINED_VERSION} ****"
23+
echo "COMBINED_VERSION=${COMBINED_VERSION}" >> $GITHUB_ENV
24+
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
2525
# Build image
26-
docker build --no-cache --build-arg COMPOSE_TAG=${COMPOSE_TAG} --build-arg COMPOSE_ALPINE_TAG=${COMPOSE_ALPINE_TAG} -t ${{ github.sha }} .
26+
docker build --no-cache --build-arg COMPOSE_RELEASE=${COMPOSE_RELEASE} --build-arg DOCKER_RELEASE=${DOCKER_RELEASE} -t ${{ github.sha }} .
2727
2828
- name: Tag image
2929
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) }}
3030
run: |
3131
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}
32-
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}
33-
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ github.sha }}
32+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}
33+
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }}
3434
docker tag ${{ github.sha }} ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
3535
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
36-
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}
37-
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ github.sha }}
36+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}
37+
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }}
3838
docker tag ${{ github.sha }} ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
3939
4040
- name: Credential check
@@ -59,8 +59,8 @@ jobs:
5959
- name: Push tags to GitHub Container Registry
6060
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.CR_USER && env.CR_PAT }}
6161
run: |
62-
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}
63-
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ github.sha }}
62+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}
63+
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }}
6464
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
6565
docker push ghcr.io/${ENDPOINT}:${BASEIMAGE}-${MODNAME}
6666
@@ -72,7 +72,7 @@ jobs:
7272
- name: Push tags to DockerHub
7373
if: ${{ github.ref == format('refs/heads/{0}-{1}', env.BASEIMAGE, env.MODNAME) && env.DOCKERUSER && env.DOCKERPASS }}
7474
run: |
75-
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}
76-
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMPOSE_VERSION }}-${{ github.sha }}
75+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}
76+
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ env.COMBINED_VERSION }}-${{ github.sha }}
7777
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}-${{ github.sha }}
7878
docker push ${ENDPOINT}:${BASEIMAGE}-${MODNAME}

Dockerfile

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,89 @@
1-
ARG COMPOSE_TAG="latest"
2-
ARG COMPOSE_ALPINE_TAG="alpine"
1+
FROM ghcr.io/linuxserver/baseimage-alpine:3.15 as buildstage
32

4-
FROM ghcr.io/linuxserver/docker-compose:amd64-${COMPOSE_TAG} as compose-amd64
5-
FROM ghcr.io/linuxserver/docker-compose:arm32v7-${COMPOSE_TAG} as compose-arm32
6-
FROM ghcr.io/linuxserver/docker-compose:arm64v8-${COMPOSE_TAG} as compose-arm64
7-
FROM ghcr.io/linuxserver/docker-compose:amd64-${COMPOSE_ALPINE_TAG} as compose-alpine-amd64
8-
FROM ghcr.io/linuxserver/docker-compose:arm32v7-${COMPOSE_ALPINE_TAG} as compose-alpine-arm32
9-
FROM ghcr.io/linuxserver/docker-compose:arm64v8-${COMPOSE_ALPINE_TAG} as compose-alpine-arm64
3+
ARG DOCKER_RELEASE
4+
ARG COMPOSE_RELEASE
105

11-
FROM ghcr.io/linuxserver/baseimage-alpine:3.12 as buildstage
6+
RUN \
7+
echo "**** install packages ****" && \
8+
apk add --no-cache \
9+
curl \
10+
git \
11+
go && \
12+
echo "**** retrieve latest docker version ****" && \
13+
if [ -z ${DOCKER_RELEASE+x} ]; then \
14+
DOCKER_RELEASE=$(curl -sX GET "https://api.github.com/repos/moby/moby/releases/latest" \
15+
| awk '/tag_name/{print $4;exit}' FS='[""]' \
16+
| sed 's|^v||'); \
17+
fi && \
18+
echo "**** grab docker ****" && \
19+
mkdir -p \
20+
/root-layer/docker-bins \
21+
/tmp/docker_x86_64 \
22+
/tmp/docker_armv7l \
23+
/tmp/docker_aarch64 && \
24+
curl -fo \
25+
/tmp/docker_x86_64.tgz -L \
26+
"https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_RELEASE}.tgz" && \
27+
tar xf \
28+
/tmp/docker_x86_64.tgz -C \
29+
/tmp/docker_x86_64 --strip-components=1 && \
30+
cp /tmp/docker_x86_64/docker /root-layer/docker-bins/docker_x86_64 && \
31+
curl -fo \
32+
/tmp/docker_armv7l.tgz -L \
33+
"https://download.docker.com/linux/static/stable/armhf/docker-${DOCKER_RELEASE}.tgz" && \
34+
tar xf \
35+
/tmp/docker_armv7l.tgz -C \
36+
/tmp/docker_armv7l --strip-components=1 && \
37+
cp /tmp/docker_armv7l/docker /root-layer/docker-bins/docker_armv7l && \
38+
curl -fo \
39+
/tmp/docker_aarch64.tgz -L \
40+
"https://download.docker.com/linux/static/stable/aarch64/docker-${DOCKER_RELEASE}.tgz" && \
41+
tar xf \
42+
/tmp/docker_aarch64.tgz -C \
43+
/tmp/docker_aarch64 --strip-components=1 && \
44+
cp /tmp/docker_aarch64/docker /root-layer/docker-bins/docker_aarch64 && \
45+
echo "**** retrieve latest compose version ****" && \
46+
if [ -z ${COMPOSE_RELEASE+x} ]; then \
47+
COMPOSE_RELEASE=$(curl -sX GET "https://api.github.com/repos/docker/compose/releases/latest" \
48+
| awk '/tag_name/{print $4;exit}' FS='[""]' \
49+
| sed 's|^v||'); \
50+
fi && \
51+
echo "**** grab compose ****" && \
52+
curl -fo \
53+
/root-layer/docker-bins/docker-compose_x86_64 -L \
54+
"https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-x86_64" && \
55+
curl -fo \
56+
/root-layer/docker-bins/docker-compose_armv7l -L \
57+
"https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-armv7" && \
58+
curl -fo \
59+
/root-layer/docker-bins/docker-compose_aarch64 -L \
60+
"https://github.com/docker/compose/releases/download/v${COMPOSE_RELEASE}/docker-compose-linux-aarch64" && \
61+
echo "**** retrieve latest compose switch version ****" && \
62+
if [ -z ${SWITCH_RELEASE+x} ]; then \
63+
SWITCH_RELEASE=$(curl -sX GET "https://api.github.com/repos/docker/compose-switch/releases/latest" \
64+
| awk '/tag_name/{print $4;exit}' FS='[""]' \
65+
| sed 's|^v||'); \
66+
fi && \
67+
echo "**** grab compose switch ****" && \
68+
curl -fo \
69+
/root-layer/docker-bins/compose-switch_x86_64 -L \
70+
"https://github.com/docker/compose-switch/releases/download/v${SWITCH_RELEASE}/docker-compose-linux-amd64" && \
71+
curl -fo \
72+
/root-layer/docker-bins/compose-switch_aarch64 -L \
73+
"https://github.com/docker/compose-switch/releases/download/v${SWITCH_RELEASE}/docker-compose-linux-arm64" && \
74+
echo "**** compile compose switch on armhf ****" && \
75+
curl -fo \
76+
/tmp/compose-switch.tar.gz -L \
77+
"https://github.com/docker/compose-switch/archive/refs/tags/v${SWITCH_RELEASE}.tar.gz" && \
78+
mkdir -p /tmp/compose-switch && \
79+
tar xf \
80+
/tmp/compose-switch.tar.gz -C \
81+
/tmp/compose-switch --strip-components=1 && \
82+
cd /tmp/compose-switch && \
83+
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 && \
84+
chmod +x /root-layer/docker-bins/* && \
85+
rm -rf /tmp/*
1286

13-
COPY --from=compose-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_x86_64
14-
COPY --from=compose-amd64 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_x86_64
15-
COPY --from=compose-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_armv7l
16-
COPY --from=compose-arm32 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_armv7l
17-
COPY --from=compose-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-ubuntu/docker-compose_aarch64
18-
COPY --from=compose-arm64 /usr/local/bin/docker /root-layer/docker-compose-ubuntu/docker_aarch64
19-
COPY --from=compose-alpine-amd64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_x86_64
20-
COPY --from=compose-alpine-amd64 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_x86_64
21-
COPY --from=compose-alpine-arm32 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_armv7l
22-
COPY --from=compose-alpine-arm32 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_armv7l
23-
COPY --from=compose-alpine-arm64 /usr/local/bin/docker-compose /root-layer/docker-compose-alpine/docker-compose_aarch64
24-
COPY --from=compose-alpine-arm64 /usr/local/bin/docker /root-layer/docker-compose-alpine/docker_aarch64
2587
COPY root/ /root-layer/
2688

2789
# runtime stage

root/etc/cont-init.d/95-docker

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#!/usr/bin/with-contenv bash
22

33
echo "**** installing docker and docker compose ****"
4-
if [ -f /usr/bin/apt ]; then
5-
DISTRONAME="ubuntu"
6-
else
7-
DISTRONAME="alpine"
8-
fi
94
ARCH=$(uname -m)
10-
if [ -f "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" ] ; then
5+
if [ -d "/docker-bins" ] ; then
116
echo "Copying over docker and docker-compose binaries"
12-
mv "/docker-compose-${DISTRONAME}/docker-compose_${ARCH}" /usr/local/bin/docker-compose
13-
mv "/docker-compose-${DISTRONAME}/docker_${ARCH}" /usr/local/bin/docker
14-
chmod +x /usr/local/bin/docker-compose
15-
rm -rf /docker-compose-ubuntu /docker-compose-alpine
7+
mkdir -p /usr/local/lib/docker/cli-plugins
8+
mv "/docker-bins/docker-compose_${ARCH}" /usr/local/lib/docker/cli-plugins/docker-compose
9+
mv "/docker-bins/docker_${ARCH}" /usr/local/bin/docker
10+
mv "/docker-bins/compose-switch_${ARCH}" /usr/local/bin/docker-compose
11+
rm -rf /docker-bins
1612
else
1713
echo "**** docker and docker-compose already installed, skipping ****"
1814
fi
@@ -30,7 +26,7 @@ if [ -S /var/run/docker.sock ]; then
3026
usermod -aG "${DOCKER_NAME}" abc
3127
fi
3228
elif [ -n "$DOCKER_HOST" ]; then
33-
echo "**** /var/run/docker.sock is not mapped, therefore, docker client will only work with a remote docker service ****"
29+
echo "**** Remote docker service $DOCKER_HOST will be used ****"
3430
else
3531
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 ****"
3632
fi

0 commit comments

Comments
 (0)