From 966b11e270d082422f19253c4eb17fec232e2ca3 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Fri, 17 Sep 2021 13:58:54 -0500 Subject: [PATCH] (#2364) Rework Linux Dockerfile Rework the Dockerfile for Linux. Move to a multi-stage build so the source code is not brought along into the final image (#2364). Add build args to select the build script and mono version to use. Remove deprecated MAINTAINER instruction and add metadata with LABEL (#2361). Add "choco.exe" to path, so both "choco" and "choco.exe" can be used, like Windows supports (#2362). Change the install location to "/opt/chocolatey" as that is more in line with the Linux filesystem hierarchy (#2360). Create the "lib" directory to prevent the warning about the directory not being found (#2363). The choco_official_wrapper is used for official builds, where the "--allow-unofficial" argument is not needed. --- docker/Dockerfile.linux | 42 ++++++++++++++++++++++++++--------- docker/README.md | 4 ++++ docker/choco_official_wrapper | 3 +++ docker/choco_wrapper | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 docker/choco_official_wrapper diff --git a/docker/Dockerfile.linux b/docker/Dockerfile.linux index f5d825a099..08b6fa0342 100644 --- a/docker/Dockerfile.linux +++ b/docker/Dockerfile.linux @@ -1,21 +1,43 @@ -FROM mono:6.12 - -MAINTAINER Justin Phelps +ARG monoversion="6.12" +FROM mono:${monoversion} as build RUN apt-get update && apt-get install git -y COPY . /usr/local/src/choco/ WORKDIR /usr/local/src/choco -RUN chmod +x build.sh -RUN chmod +x zip.sh -RUN ./build.sh +RUN chmod +x *.sh + +ARG buildscript="build.sh" +RUN ./$buildscript + +RUN if [ "$buildscript" = "build.official.sh" ]; then \ + cp docker/choco_official_wrapper code_drop/chocolatey/console/choco_wrapper; \ + else \ + cp docker/choco_wrapper code_drop/chocolatey/console/choco_wrapper; \ + fi; + + +ARG monoversion="6.12" +FROM mono:${monoversion} as install + +ARG monoversion="6.12" +LABEL org.opencontainers.image.url="https://chocolatey.org/" +LABEL org.opencontainers.image.documentation="https://docs.chocolatey.org/" +LABEL org.opencontainers.image.source="https://github.com/chocolatey/choco" +LABEL org.opencontainers.image.vendor="Chocolatey Software, Inc" +LABEL org.opencontainers.image.licenses="Apache-2.0" +LABEL org.opencontainers.image.title="Chocolatey" +LABEL org.opencontainers.image.description="Chocolatey Client running on Mono" +LABEL org.opencontainers.image.authors="https://chocolatey.org/support" +LABEL org.opencontainers.image.base.name="index.docker.io/library/mono:${monoversion}" -WORKDIR /usr/local/bin -RUN ln -s /usr/local/src/choco/code_drop/chocolatey +ENV ChocolateyInstall /opt/chocolatey -COPY docker/choco_wrapper /usr/local/bin/choco +COPY --from=build /usr/local/src/choco/code_drop/chocolatey/console /opt/chocolatey -ENV ChocolateyInstall /usr/local/bin/chocolatey +RUN mkdir /opt/chocolatey/lib; \ + cp /opt/chocolatey/choco_wrapper usr/local/bin/choco; \ + cp /opt/chocolatey/choco_wrapper usr/local/bin/choco.exe; WORKDIR /root diff --git a/docker/README.md b/docker/README.md index 504a96261a..fd6599ae81 100644 --- a/docker/README.md +++ b/docker/README.md @@ -8,5 +8,9 @@ To build this image yourself, follow these steps: 1. Clone down the repository using `git clone https://github.com/chocolatey/choco.git`. 1. Change directories to the root of the repository. 1. Run the docker build command. `docker build -t mono-choco -f docker/Dockerfile.linux .` (the trailing . is important) + To build a official version, add the argument `--build-arg buildscript=build.official.sh` + To build a debug version, add the argument `--build-arg buildscript=build.official.sh` + To change the version of mono used, add the argument `--build-arg monoversion=mono-tag` 1. Run your new image using the command `docker run -ti --rm mono-choco /bin/bash` 1. Test choco by running `choco -h`. You should see the help message from choco.exe. + diff --git a/docker/choco_official_wrapper b/docker/choco_official_wrapper new file mode 100644 index 0000000000..6005de42d5 --- /dev/null +++ b/docker/choco_official_wrapper @@ -0,0 +1,3 @@ +#!/bin/bash + +mono /opt/chocolatey/choco.exe "$@" diff --git a/docker/choco_wrapper b/docker/choco_wrapper index 745cdf43ce..881390888f 100755 --- a/docker/choco_wrapper +++ b/docker/choco_wrapper @@ -1,3 +1,3 @@ #!/bin/bash -mono /usr/local/bin/chocolatey/console/choco.exe "$@" --allow-unofficial +mono /opt/chocolatey/choco.exe "$@" --allow-unofficial