From 2bef4d83886ea13f3dc45a5bb16b997a6eae1acd Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 15 Jul 2020 12:28:52 -0600 Subject: Install dotnet SDK * Include the latest dotnet SDK in the /opt/asdf/installs directory. * Update CHANGELOG and bump version * Compress large directories --- .gitlab/test.yml | 1 - CHANGELOG.md | 4 ++++ Gemfile.lock | 2 +- bin/docker-build | 2 +- config/files/.bashrc | 9 ++++++++ config/install.sh | 46 +++++++++++++++++++++++++++++---------- lib/license/finder/ext/dotnet.rb | 8 ++++--- lib/license/management/version.rb | 2 +- 8 files changed, 55 insertions(+), 19 deletions(-) diff --git a/.gitlab/test.yml b/.gitlab/test.yml index 00c9434..6d0dcae 100644 --- a/.gitlab/test.yml +++ b/.gitlab/test.yml @@ -35,7 +35,6 @@ lint: variables: GIT_DEPTH: "10" GIT_STRATEGY: fetch - LOG_LEVEL: debug cache: key: ${CI_COMMIT_REF_SLUG} paths: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2168955..a310c65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # GitLab License management changelog +## v3.19.0 + +- Include the latest LTS of the .NET SDK in the Docker image. (!191) + ## v3.18.1 - Fix failing composer tests. diff --git a/Gemfile.lock b/Gemfile.lock index 27474e8..b3cbb88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT PATH remote: . specs: - license-management (3.18.1) + license-management (3.19.0) license_finder (~> 6.6.0) GEM diff --git a/bin/docker-build b/bin/docker-build index 6f111fe..abc46c1 100755 --- a/bin/docker-build +++ b/bin/docker-build @@ -9,7 +9,7 @@ IMAGE_NAME=${IMAGE_NAME:-$(basename "$PWD"):latest} export DOCKER_BUILDKIT=1 if command -v docker; then - docker build --progress=plain --network=host --cache-from "$LATEST_IMAGE" -t "$IMAGE_NAME" . + docker build --network=host --cache-from "$LATEST_IMAGE" -t "$IMAGE_NAME" . else echo "Install docker: https://docs.docker.com/engine/installation/" exit 1 diff --git a/config/files/.bashrc b/config/files/.bashrc index 81afcb8..388f93d 100644 --- a/config/files/.bashrc +++ b/config/files/.bashrc @@ -60,7 +60,16 @@ function enable_dev_mode() { } inflate /opt/asdf.tar.zst /opt +inflate /opt/gitlab/.cache.tar.zst /opt/gitlab +inflate /opt/gitlab/.config.tar.zst /opt/gitlab +inflate /opt/gitlab/.m2.tar.zst /opt/gitlab +inflate /opt/gitlab/embedded.tar.zst /opt/gitlab +inflate /usr/include.tar.zst /usr +inflate /usr/lib/elixir.tar.zst /usr/lib +inflate /usr/lib/erlang.tar.zst /usr/lib inflate /usr/lib/gcc.tar.zst /usr/lib +inflate /usr/lib/git-core.tar.zst /usr/lib +inflate /usr/lib/llvm-7.tar.zst /usr/lib inflate /usr/lib/rustlib.tar.zst /usr/lib # shellcheck source=/dev/null diff --git a/config/install.sh b/config/install.sh index 0de9b1c..834dff8 100644 --- a/config/install.sh +++ b/config/install.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -euo pipefail +set -exuo pipefail export DEBIAN_FRONTEND=noninteractive @@ -75,15 +75,6 @@ apt-get install -y --no-install-recommends \ zstd echo -e "section_end:$(date +%s):install_packages\r\e[0K" -echo -e "section_start:$(date +%s):install_dotnet\r\e[0K==> Installing dotnet/mono…" -wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg -wget -q -O /etc/apt/sources.list.d/microsoft-prod.list https://packages.microsoft.com/config/debian/10/prod.list -apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF -echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list - -curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -echo -e "section_end:$(date +%s):install_dotnet\r\e[0K" - echo -e "section_start:$(date +%s):install_asdf\r\e[0K==> Installing asdf…" dpkg --install "$(find /opt/toolcache/ -name "license-management*.deb")" rm -fr /root @@ -113,6 +104,17 @@ done wait echo -e "section_end:$(date +%s):install_asdf\r\e[0K" +echo -e "section_start:$(date +%s):install_dotnet\r\e[0K==> Installing dotnet/mono…" +wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg +wget -q -O /etc/apt/sources.list.d/microsoft-prod.list https://packages.microsoft.com/config/debian/10/prod.list +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF +echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list + +curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe +curl -o /tmp/dotnet-install.sh https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.sh +bash /tmp/dotnet-install.sh --install-dir /opt/asdf/installs/dotnet/latest --channel LTS --version latest +echo -e "section_end:$(date +%s):install_dotnet\r\e[0K" + echo -e "section_start:$(date +%s):cleanup\r\e[0K==> Beginning cleanup…" apt purge -y libx11-6 libwayland-client0 apt autoremove -y @@ -180,15 +182,35 @@ zstd_command="/usr/bin/zstd -19 -T0" cd /opt tar --use-compress-program "$zstd_command" -cf /opt/asdf.tar.zst asdf & -cd /usr/lib -tar --use-compress-program "$zstd_command" -cf /usr/lib/gcc.tar.zst gcc & +cd /opt/gitlab +tar --use-compress-program "$zstd_command" -cf /opt/gitlab/.cache.tar.zst .cache & +tar --use-compress-program "$zstd_command" -cf /opt/gitlab/.config.tar.zst .config & +tar --use-compress-program "$zstd_command" -cf /opt/gitlab/.m2.tar.zst .m2 & +tar --use-compress-program "$zstd_command" -cf /opt/gitlab/embedded.tar.zst embedded & + +cd /usr +tar --use-compress-program "$zstd_command" -cf /usr/include.tar.zst include & cd /usr/lib +tar --use-compress-program "$zstd_command" -cf /usr/lib/elixir.tar.zst elixir & +tar --use-compress-program "$zstd_command" -cf /usr/lib/erlang.tar.zst erlang & +tar --use-compress-program "$zstd_command" -cf /usr/lib/gcc.tar.zst gcc & +tar --use-compress-program "$zstd_command" -cf /usr/lib/git-core.tar.zst git-core & +tar --use-compress-program "$zstd_command" -cf /usr/lib/llvm-7.tar.zst llvm-7 & tar --use-compress-program "$zstd_command" -cf /usr/lib/rustlib.tar.zst rustlib & wait rm -fr \ /opt/asdf/ \ + /opt/gitlab/.m2 \ + /opt/gitlab/.cache \ + /opt/gitlab/.config \ + /opt/gitlab/embedded \ + /usr/include \ + /usr/lib/elixir \ + /usr/lib/erlang \ /usr/lib/gcc \ + /usr/lib/git-core \ + /usr/lib/llvm-7 \ /usr/lib/rustlib echo -e "section_end:$(date +%s):compress_files\r\e[0K" diff --git a/lib/license/finder/ext/dotnet.rb b/lib/license/finder/ext/dotnet.rb index c5ff485..e9e0490 100644 --- a/lib/license/finder/ext/dotnet.rb +++ b/lib/license/finder/ext/dotnet.rb @@ -9,12 +9,14 @@ module LicenseFinder project_path.glob('*.fsproj') end + def installed?(*) + File.exist?('/opt/asdf/installs/dotnet/latest/dotnet') + end + def prepare - shell.execute(['apt-get', :update, '-q']) - shell.execute(['apt-get', :install, '-y', '--no-install-recommends', 'dotnet-sdk-3.1']) shell.execute([:mkdir, '-p', vendor_path.to_s]) unless vendor_path.exist? shell.execute([ - :dotnet, + '/opt/asdf/installs/dotnet/latest/dotnet', :restore, detected_package_path.to_s, '--no-cache', '--packages', vendor_path.to_s, diff --git a/lib/license/management/version.rb b/lib/license/management/version.rb index 1ba7279..72c1491 100644 --- a/lib/license/management/version.rb +++ b/lib/license/management/version.rb @@ -2,6 +2,6 @@ module License module Management - VERSION = '3.18.1' + VERSION = '3.19.0' end end -- cgit v1.2.3 From 554dee2716b13a06f7b43d7a9b8d3c7af59785c0 Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 16 Jul 2020 20:28:21 -0600 Subject: Install mono/nuget at build time * Install ca-certificates-mono * Download *.deb files to /opt/toolcache/mono --- CHANGELOG.md | 1 + Dockerfile | 21 +++++++++++++++++---- config/install.sh | 2 +- lib/license/finder/ext/dotnet.rb | 4 ++-- lib/license/finder/ext/nuget.rb | 16 ++++++++++------ lib/license/management.rb | 3 ++- spec/support/proxy_helper.rb | 8 +++----- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a310c65..38d1587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v3.19.0 - Include the latest LTS of the .NET SDK in the Docker image. (!191) +- Include the latest LTS of Mono in the Docker image. (!193) ## v3.18.1 diff --git a/Dockerfile b/Dockerfile index a5119c3..50ee6b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,21 @@ # syntax = docker/dockerfile:experimental -FROM debian:stable AS deb-builder +FROM debian:stable AS gem-builder WORKDIR /build COPY . ./ -RUN ./bin/omnibus setup -RUN ./bin/omnibus build license_management +RUN ./bin/omnibus setup && \ + ./bin/omnibus build license_management && \ + mkdir -p /opt/toolcache && \ + cp pkg/*.deb /opt/toolcache/ + +FROM debian:stable AS mono-builder +RUN apt-get update -q +RUN apt-get install --no-install-recommends -y apt-transport-https dirmngr gnupg ca-certificates +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF +RUN echo "deb https://download.mono-project.com/repo/debian stable-buster main" | tee /etc/apt/sources.list.d/mono-official-stable.list +RUN apt-get update -q +RUN mv /etc/apt/apt.conf.d/docker-clean /etc/apt/apt.conf.d/docker-clean.bak +RUN apt-get install -y --no-install-recommends nuget referenceassemblies-pcl ca-certificates-mono +RUN mkdir -p /opt/toolcache && cp /var/cache/apt/archives/*.deb /opt/toolcache/ FROM debian:stable-slim ENV ASDF_DATA_DIR="/opt/asdf" @@ -12,7 +24,8 @@ ENV TERM="xterm" WORKDIR /opt/gitlab COPY config/01_nodoc /etc/dpkg/dpkg.cfg.d/01_nodoc RUN mkdir -p /opt/toolcache -COPY --from=deb-builder /build/pkg/*.deb /opt/toolcache/ +COPY --from=gem-builder /opt/toolcache/*.deb /opt/toolcache/ +COPY --from=mono-builder /opt/toolcache/*.deb /opt/toolcache/mono/ COPY config/install.sh /opt/install.sh RUN bash /opt/install.sh COPY run.sh / diff --git a/config/install.sh b/config/install.sh index 834dff8..8d555c4 100644 --- a/config/install.sh +++ b/config/install.sh @@ -76,7 +76,7 @@ apt-get install -y --no-install-recommends \ echo -e "section_end:$(date +%s):install_packages\r\e[0K" echo -e "section_start:$(date +%s):install_asdf\r\e[0K==> Installing asdf…" -dpkg --install "$(find /opt/toolcache/ -name "license-management*.deb")" +dpkg --install /opt/toolcache/license*.deb rm -fr /root ln -s /opt/gitlab /root diff --git a/lib/license/finder/ext/dotnet.rb b/lib/license/finder/ext/dotnet.rb index e9e0490..d2cb998 100644 --- a/lib/license/finder/ext/dotnet.rb +++ b/lib/license/finder/ext/dotnet.rb @@ -18,10 +18,10 @@ module LicenseFinder shell.execute([ '/opt/asdf/installs/dotnet/latest/dotnet', :restore, detected_package_path.to_s, + '--locked-mode', '--no-cache', '--packages', vendor_path.to_s, - '--locked-mode', - '--verbosity', :detailed + '--verbosity', :normal ]) end diff --git a/lib/license/finder/ext/nuget.rb b/lib/license/finder/ext/nuget.rb index 6fb2553..93985ba 100644 --- a/lib/license/finder/ext/nuget.rb +++ b/lib/license/finder/ext/nuget.rb @@ -3,22 +3,24 @@ module LicenseFinder class Nuget def prepare - shell.execute(['apt-get', :update, '-q']) - shell.execute(['apt-get', :install, '-y', '--no-install-recommends', 'mono-complete']) + shell.execute(['apt-get', :install, '-y', '/opt/toolcache/mono/*.deb']) shell.execute([:mkdir, '-p', vendor_path.to_s]) unless vendor_path.exist? - Dir.chdir(project_path) do shell.execute([ :mono, '/usr/local/bin/nuget.exe', :restore, detected_package_path, - '-Verbosity detailed', - '-PackagesDirectory', vendor_path, + '-LockedMode', '-NoCache', - '-LockedMode' + '-PackagesDirectory', vendor_path, + '-Verbosity', :normal ]) end end + def installed?(*args) + File.exist?('/usr/local/bin/nuget.exe') + end + def current_packages dependencies.map do |dependency| nupkg = vendor_path.glob("**/#{dependency.name}*.nupkg")[0] @@ -45,6 +47,8 @@ module LicenseFinder [] end + private + def vendor_path @vendor_path ||= Pathname.pwd.join('.gitlab', 'cache', 'vendor') end diff --git a/lib/license/management.rb b/lib/license/management.rb index 58310f7..0824157 100644 --- a/lib/license/management.rb +++ b/lib/license/management.rb @@ -26,7 +26,8 @@ module License def self.logger @logger ||= Logger.new(STDOUT, level: ENV.fetch('LOG_LEVEL', Logger::WARN)).tap do |x| x.formatter = proc do |_severity, _datetime, _progname, message| - "[v#{VERSION}] #{message}\n" + prefix = message.start_with?("\n") ? "" : "[v#{VERSION}] " + "#{prefix}#{message}\n" end end end diff --git a/spec/support/proxy_helper.rb b/spec/support/proxy_helper.rb index 700fe38..a07ee84 100644 --- a/spec/support/proxy_helper.rb +++ b/spec/support/proxy_helper.rb @@ -5,11 +5,9 @@ module ProxyHelper def generate_self_signed_certificate_for(host) Dir.chdir License::Management.root.join('tmp') do - system([ - "rm -f #{host}.*", - "/usr/bin/openssl req -x509 -newkey rsa:4096 -keyout #{host}.key -out #{host}.crt -days 999 -nodes -subj '/C=/ST=/L=/O=/OU=/CN=*.test' -addext 'subjectAltName=DNS:nuget.test,DNS:rubygems.test,DNS:goproxy.test'", - "cat #{host}.* > #{host}.pem" - ].join("&&")) + system("rm -f #{host}.*") + system("/usr/bin/openssl req -x509 -newkey rsa:4096 -keyout #{host}.key -out #{host}.crt -days 999 -nodes -subj '/C=/ST=/L=/O=/OU=/CN=*.test' -addext 'subjectAltName=DNS:nuget.test,DNS:rubygems.test,DNS:goproxy.test'") + system("cat #{host}.* > #{host}.pem") end end -- cgit v1.2.3