Skip to content

Commit

Permalink
(chocolatey#2364) Rework Linux Dockerfile
Browse files Browse the repository at this point in the history
Rework the Dockerfile for Linux. Move to a multi-stage build so the
source code is not brought along into the final image (chocolatey#2364). Add
build args to select the build script and mono version to use. Remove
deprecated MAINTAINER instruction and add metadata with LABEL (chocolatey#2361).
Add "choco.exe" to path, so both "choco" and "choco.exe" can be used,
like Windows supports (chocolatey#2362). Change the install location to
"/opt/chocolatey" as that is more in line with the Linux filesystem
hierarchy (chocolatey#2360). Create the "lib" directory to prevent the warning
about the directory not being found (chocolatey#2363).

The choco_official_wrapper is used for official builds, where the
"--allow-unofficial" argument is not needed.
  • Loading branch information
TheCakeIsNaOH committed Sep 17, 2021
1 parent 2f554cb commit 1833156
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
42 changes: 32 additions & 10 deletions docker/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
FROM mono:6.12

MAINTAINER Justin Phelps <linuturk@onitato.com>
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
4 changes: 4 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

3 changes: 3 additions & 0 deletions docker/choco_official_wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

mono /opt/chocolatey/choco.exe "$@"
2 changes: 1 addition & 1 deletion docker/choco_wrapper
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

mono /usr/local/bin/chocolatey/console/choco.exe "$@" --allow-unofficial
mono /opt/chocolatey/choco.exe "$@" --allow-unofficial

0 comments on commit 1833156

Please sign in to comment.