fix: use docker volumes to share context between containers
This commit is contained in:
@@ -83,26 +83,37 @@ jobs:
|
|||||||
IMAGE_NAME="${{ env.REGISTRY }}/damien/${{ matrix.image }}"
|
IMAGE_NAME="${{ env.REGISTRY }}/damien/${{ matrix.image }}"
|
||||||
|
|
||||||
echo "Building ${IMAGE_NAME}:latest ..."
|
echo "Building ${IMAGE_NAME}:latest ..."
|
||||||
echo "Context: /src/images/${{ matrix.image }}"
|
|
||||||
|
|
||||||
# Create auth config for buildkit
|
# Create a unique volume name for this build
|
||||||
mkdir -p /root/.docker
|
VOLUME_NAME="buildkit-ctx-$$"
|
||||||
|
|
||||||
|
# Create a docker volume and copy source into it
|
||||||
|
docker volume create ${VOLUME_NAME}
|
||||||
|
docker run --rm -v ${VOLUME_NAME}:/context -v /src/images/${{ matrix.image }}:/src:ro alpine sh -c "cp -r /src/* /context/"
|
||||||
|
|
||||||
|
# Create auth config in another volume
|
||||||
|
AUTH_VOLUME="buildkit-auth-$$"
|
||||||
|
docker volume create ${AUTH_VOLUME}
|
||||||
AUTH=$(echo -n "${REGISTRY_USER}:${REGISTRY_TOKEN}" | base64 | tr -d '\n')
|
AUTH=$(echo -n "${REGISTRY_USER}:${REGISTRY_TOKEN}" | base64 | tr -d '\n')
|
||||||
cat > /root/.docker/config.json <<EOF
|
docker run --rm -v ${AUTH_VOLUME}:/auth alpine sh -c "mkdir -p /auth && cat > /auth/config.json << 'AUTHEOF'
|
||||||
{
|
{
|
||||||
"auths": {
|
\"auths\": {
|
||||||
"${{ env.REGISTRY }}": {
|
\"${{ env.REGISTRY }}\": {
|
||||||
"auth": "${AUTH}"
|
\"auth\": \"${AUTH}\"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
AUTHEOF"
|
||||||
|
|
||||||
# Run buildkit in daemonless mode via docker socket
|
# Debug: show context content
|
||||||
|
echo "Context content:"
|
||||||
|
docker run --rm -v ${VOLUME_NAME}:/context alpine ls -la /context/
|
||||||
|
|
||||||
|
# Run buildkit in daemonless mode
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--privileged \
|
--privileged \
|
||||||
-v /src/images/${{ matrix.image }}:/context:ro \
|
-v ${VOLUME_NAME}:/context:ro \
|
||||||
-v /root/.docker/config.json:/root/.docker/config.json:ro \
|
-v ${AUTH_VOLUME}:/root/.docker:ro \
|
||||||
--entrypoint buildctl-daemonless.sh \
|
--entrypoint buildctl-daemonless.sh \
|
||||||
moby/buildkit:master \
|
moby/buildkit:master \
|
||||||
build \
|
build \
|
||||||
@@ -111,4 +122,7 @@ jobs:
|
|||||||
--local dockerfile=/context \
|
--local dockerfile=/context \
|
||||||
--output type=image,name=${IMAGE_NAME}:latest,push=true
|
--output type=image,name=${IMAGE_NAME}:latest,push=true
|
||||||
|
|
||||||
|
# Cleanup volumes
|
||||||
|
docker volume rm ${VOLUME_NAME} ${AUTH_VOLUME} || true
|
||||||
|
|
||||||
echo "✅ Pushed ${IMAGE_NAME}:latest"
|
echo "✅ Pushed ${IMAGE_NAME}:latest"
|
||||||
|
|||||||
Reference in New Issue
Block a user