From 16481af8192e2c5eb2f67e38bb3f5bec7171d61b Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Mon, 24 Jul 2023 00:51:10 +0300 Subject: [PATCH 1/2] docker: add core22 to the image This also makes Ubuntu 22.04 and snapcraft/stable the default for the builder and runner image. Moves repeated code from Dockerfile into a script to avoid copypasta. --- docker/Dockerfile | 41 ++++++++++++----------------------------- docker/README.md | 13 ++++++++----- docker/prepare.sh | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 docker/prepare.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index bffb2192c4..a481c1229e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,5 @@ -ARG RISK=edge -ARG UBUNTU=xenial +ARG RISK=stable +ARG UBUNTU=22.04 FROM ubuntu:$UBUNTU as builder ARG RISK @@ -7,36 +7,14 @@ ARG UBUNTU RUN echo "Building snapcraft:$RISK in ubuntu:$UBUNTU" # Grab dependencies -RUN apt-get update -RUN apt-get dist-upgrade --yes -RUN apt-get install --yes \ +RUN apt-get update && apt-get -y dist-upgrade && apt-get -y install \ curl \ jq \ squashfs-tools -# Grab the core snap (for backwards compatibility) from the stable channel and -# unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core' | jq '.download_url' -r) --output core.snap -RUN mkdir -p /snap/core -RUN unsquashfs -d /snap/core/current core.snap - -# Grab the core18 snap (which snapcraft uses as a base) from the stable channel -# and unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core18' | jq '.download_url' -r) --output core18.snap -RUN mkdir -p /snap/core18 -RUN unsquashfs -d /snap/core18/current core18.snap - -# Grab the core20 snap (which snapcraft uses as a base) from the stable channel -# and unpack it in the proper place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/core20' | jq '.download_url' -r) --output core20.snap -RUN mkdir -p /snap/core20 -RUN unsquashfs -d /snap/core20/current core20.snap - -# Grab the snapcraft snap from the $RISK channel and unpack it in the proper -# place. -RUN curl -L $(curl -H 'X-Ubuntu-Series: 16' 'https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel='$RISK | jq '.download_url' -r) --output snapcraft.snap -RUN mkdir -p /snap/snapcraft -RUN unsquashfs -d /snap/snapcraft/current snapcraft.snap +# Download and unpack snap bases and snapcraft as a snap +COPY --chmod=755 prepare.sh . +RUN ./prepare.sh # Fix Python3 installation: Make sure we use the interpreter from # the snapcraft snap: @@ -58,11 +36,16 @@ FROM ubuntu:$UBUNTU COPY --from=builder /snap/core /snap/core COPY --from=builder /snap/core18 /snap/core18 COPY --from=builder /snap/core20 /snap/core20 +COPY --from=builder /snap/core20 /snap/core22 COPY --from=builder /snap/snapcraft /snap/snapcraft COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft # Generate locale and install dependencies. -RUN apt-get update && apt-get dist-upgrade --yes && apt-get install --yes snapd sudo locales && locale-gen en_US.UTF-8 +RUN apt-get update && apt-get -y dist-upgrade && apt-get -y install \ + snapd \ + sudo \ + locales \ + && locale-gen en_US.UTF-8 # Set the proper environment. ENV LANG="en_US.UTF-8" diff --git a/docker/README.md b/docker/README.md index 528fb9acfb..b9e86498e2 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,16 +1,19 @@ # Creating docker containers for snapcraft -By default the `Dockerfile` builds Ubuntu 16.04 (Xenial) image with `snapcraft` from the `edge` channel. +By default the `Dockerfile` builds Ubuntu 22.04 (Jellyfish) image with +`snapcraft` from the `stable` channel: docker build . --no-cache -It is however possible to choose the base Ubuntu version and the Snapcraft channel (risk levels): +To choose different Ubuntu version and the Snapcraft channel (risk levels), +use use `--build-arg RISK=` and `--build-arg UBUNTU=` options: + + docker build . --no-cache --build-arg RISK=beta --build-arg UBUNTU=bionic + +Possible RISK values: - `edge` - `beta` - `candidate` - `stable` -To do that, use `--build-arg RISK=` and `--build-arg UBUNTU=` arguments: - - docker build . --no-cache --build-arg RISK=beta --build-arg UBUNTU=bionic diff --git a/docker/prepare.sh b/docker/prepare.sh new file mode 100644 index 0000000000..a56d03f407 --- /dev/null +++ b/docker/prepare.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -xeo pipefail + + +echo "--- unpacking bases for snapcraft/$RISK ---" + +# Grab the core snaps (which snapcraft uses as a base) from the stable channel +# and unpack them in the proper place. +BASES="core core18 core20 core22" +for base in $BASES; do + curl -L "$(curl -H "X-Ubuntu-Series: 16" "https://api.snapcraft.io/api/v1/snaps/details/$base" | jq ".download_url" -r)" --output "$base.snap" + mkdir -p "/snap/$base" + unsquashfs -d "/snap/$base/current" "$base.snap" +done + + +echo "--- unpacking snapcraft/$RISK ---" + +# Grab the snapcraft snap from the $RISK channel and unpack it in the proper +# place. +curl -L "$(curl -H "X-Ubuntu-Series: 16" "https://api.snapcraft.io/api/v1/snaps/details/snapcraft?channel=$RISK" | jq ".download_url" -r)" --output snapcraft.snap +mkdir -p /snap/snapcraft +unsquashfs -d /snap/snapcraft/current snapcraft.snap From 3a8081e49f500799a6bc9aea94f6ddc16fe5cafb Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Wed, 27 Sep 2023 08:10:24 +0300 Subject: [PATCH 2/2] Fix source for `core22` --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index a481c1229e..85f2f0ac55 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -36,7 +36,7 @@ FROM ubuntu:$UBUNTU COPY --from=builder /snap/core /snap/core COPY --from=builder /snap/core18 /snap/core18 COPY --from=builder /snap/core20 /snap/core20 -COPY --from=builder /snap/core20 /snap/core22 +COPY --from=builder /snap/core22 /snap/core22 COPY --from=builder /snap/snapcraft /snap/snapcraft COPY --from=builder /snap/bin/snapcraft /snap/bin/snapcraft