From abe58349912ff15469effce39583d156bb0a9e2d Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Sat, 9 May 2020 13:30:11 +0100 Subject: [PATCH] provision and use a apt (aka debian) repository --- .gitignore | 13 ++++-- Vagrantfile | 2 + .../hello-world/Makefile | 19 ++++++++ .../hello-world/debian/changelog | 5 +++ .../hello-world/debian/compat | 1 + .../hello-world/debian/control | 17 +++++++ .../hello-world/debian/copyright | 24 ++++++++++ .../hello-world/debian/rules | 5 +++ .../hello-world/debian/source/format | 1 + hello-world-debian-package/hello-world/main.c | 6 +++ provision/provision-base.sh | 16 +++++++ provision/provision-nexus.sh | 45 +++++++++++++++++++ .../src/main/groovy/provision.groovy | 6 +++ provision/use-apt-repository.sh | 38 ++++++++++++++++ 14 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 hello-world-debian-package/hello-world/Makefile create mode 100644 hello-world-debian-package/hello-world/debian/changelog create mode 100644 hello-world-debian-package/hello-world/debian/compat create mode 100644 hello-world-debian-package/hello-world/debian/control create mode 100644 hello-world-debian-package/hello-world/debian/copyright create mode 100755 hello-world-debian-package/hello-world/debian/rules create mode 100644 hello-world-debian-package/hello-world/debian/source/format create mode 100644 hello-world-debian-package/hello-world/main.c create mode 100644 provision/use-apt-repository.sh diff --git a/.gitignore b/.gitignore index 32d7f40..6d184f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,12 @@ -.vagrant/ -.idea/ -provision/provision-nexus/sources/ +.vagrant/ +.idea/ +provision/provision-nexus/sources/ shared/ binaries/ +/hello-world-debian-package/hello-world/debian/.debhelper/ +/hello-world-debian-package/hello-world_* +/hello-world-debian-package/hello-world-* +/hello-world-debian-package/hello-world/debian/hello-world* +/hello-world-debian-package/hello-world/debian/debhelper-build-stamp +/hello-world-debian-package/hello-world/debian/files +/hello-world-debian-package/hello-world/hello-world diff --git a/Vagrantfile b/Vagrantfile index 2c976df..727720d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -11,6 +11,7 @@ Vagrant.configure(2) do |config| lv.cpus = 4 lv.cpu_mode = 'host-passthrough' lv.keymap = 'pt' + lv.random :model => 'random' end config.vm.provider :virtualbox do |vb| @@ -31,6 +32,7 @@ Vagrant.configure(2) do |config| config.vm.provision :shell, path: 'provision/provision-nexus.sh' config.vm.provision :shell, path: 'provision/use-docker-repository.sh' config.vm.provision :shell, path: 'provision/use-raw-repository.sh' + config.vm.provision :shell, path: 'provision/use-apt-repository.sh' config.vm.provision :shell, path: 'provision/use-maven-repository-from-mvn.sh' config.vm.provision :shell, path: 'provision/use-maven-repository-from-gradle.sh' config.vm.provision :shell, path: 'provision/use-nuget-repository.sh' diff --git a/hello-world-debian-package/hello-world/Makefile b/hello-world-debian-package/hello-world/Makefile new file mode 100644 index 0000000..3f88e56 --- /dev/null +++ b/hello-world-debian-package/hello-world/Makefile @@ -0,0 +1,19 @@ +prefix = /usr + +all: hello-world + +hello-world: main.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDCFLAGS) -o $@ $^ + +install: hello-world + install -D hello-world $(DESTDIR)$(prefix)/bin/hello-world + +clean: + rm -f hello-world + +distclean: clean + +uninstall: + rm -f $(DESTDIR)$(prefix)/bin/hello-world + +.PHONY: all install clean distclean uninstall diff --git a/hello-world-debian-package/hello-world/debian/changelog b/hello-world-debian-package/hello-world/debian/changelog new file mode 100644 index 0000000..50da73b --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/changelog @@ -0,0 +1,5 @@ +hello-world (1.0.0) bionic; urgency=low + + * Hello World. + + -- Alice Doe Sat, 9 May 2020 08:09:10 +0100 diff --git a/hello-world-debian-package/hello-world/debian/compat b/hello-world-debian-package/hello-world/debian/compat new file mode 100644 index 0000000..9a03714 --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/compat @@ -0,0 +1 @@ +10 \ No newline at end of file diff --git a/hello-world-debian-package/hello-world/debian/control b/hello-world-debian-package/hello-world/debian/control new file mode 100644 index 0000000..d8abd4e --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/control @@ -0,0 +1,17 @@ +Source: hello-world +Section: misc +Priority: optional +Maintainer: "Alice Doe" +Build-Depends: debhelper (>=11~) +Standards-Version: 4.1.4 +Homepage: https://example.com + +Package: hello-world +Architecture: any +Multi-Arch: foreign +Depends: ${misc:Depends}, ${shlibs:Depends} +Description: classic hello world + The classic hello world application. + . + It serves as an example package that is used + to test the nexus apt-hosted repository. diff --git a/hello-world-debian-package/hello-world/debian/copyright b/hello-world-debian-package/hello-world/debian/copyright new file mode 100644 index 0000000..74ce6bd --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/copyright @@ -0,0 +1,24 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ + +Files: * +Copyright: 2020 Alice Doe +License: MIT + +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + . + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + . + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. diff --git a/hello-world-debian-package/hello-world/debian/rules b/hello-world-debian-package/hello-world/debian/rules new file mode 100755 index 0000000..4d68614 --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/rules @@ -0,0 +1,5 @@ +#!/usr/bin/make -f +export DH_VERBOSE=1 + +%: + dh $@ diff --git a/hello-world-debian-package/hello-world/debian/source/format b/hello-world-debian-package/hello-world/debian/source/format new file mode 100644 index 0000000..9f67427 --- /dev/null +++ b/hello-world-debian-package/hello-world/debian/source/format @@ -0,0 +1 @@ +3.0 (native) \ No newline at end of file diff --git a/hello-world-debian-package/hello-world/main.c b/hello-world-debian-package/hello-world/main.c new file mode 100644 index 0000000..160f760 --- /dev/null +++ b/hello-world-debian-package/hello-world/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, world!\n"); + return 0; +} diff --git a/provision/provision-base.sh b/provision/provision-base.sh index 0ced53a..cb13555 100644 --- a/provision/provision-base.sh +++ b/provision/provision-base.sh @@ -27,6 +27,22 @@ update-grub2 # update the package cache. apt-get -y update +# install a EGD (Entropy Gathering Daemon). +# NB the host should have an EGD and expose/virtualize it to the guest. +# on libvirt there's virtio-rng which will read from the host /dev/random device +# so your host should have a TRNG (True RaNdom Generator) with rng-tools +# reading from it and feeding it into /dev/random or have the haveged +# daemon running. +# see https://wiki.qemu.org/Features/VirtIORNG +# see https://wiki.archlinux.org/index.php/Rng-tools +# see https://www.kernel.org/doc/Documentation/hw_random.txt +# see https://hackaday.com/2017/11/02/what-is-entropy-and-how-do-i-get-more-of-it/ +# see cat /sys/devices/virtual/misc/hw_random/rng_current +# see cat /proc/sys/kernel/random/entropy_avail +# see rngtest -c 1000 "$GNUPGHOME/apt-hosted-gpg-batch" <"$GNUPGHOME/gpg-agent.conf" </vagrant/shared/apt-hosted-public.key +gpg \ + --export-secret-key \ + --armor \ + --pinentry-mode loopback \ + --passphrase abracadabra \ + "apt-hosted@$nexus_domain" \ + >/vagrant/shared/apt-hosted-private.key +gpgconf --kill gpg-agent +rm -rf "$GNUPGHOME" +unset GNUPGHOME + + # configure nexus with the groovy script. bash /vagrant/provision/execute-provision.groovy-script.sh + # configure nexus ldap with a groovy script. if [ "$config_authentication" = 'ldap' ]; then bash /vagrant/provision/execute-provision-ldap.groovy-script.sh diff --git a/provision/provision-nexus/src/main/groovy/provision.groovy b/provision/provision-nexus/src/main/groovy/provision.groovy index 028af79..d838aa5 100644 --- a/provision/provision-nexus/src/main/groovy/provision.groovy +++ b/provision/provision-nexus/src/main/groovy/provision.groovy @@ -33,6 +33,12 @@ capabilityRegistry.all.findAll {it.context().type().toString().startsWith("Outre repository.createRawHosted("adhoc-package", "default", false, WritePolicy.ALLOW_ONCE) +// create a apt repository backed by the default blob store. +// see https://help.sonatype.com/repomanager3/formats/apt-repositories +pgpPrivateKey = new File('/vagrant/shared/apt-hosted-private.key').getText('UTF-8') +repository.createAptHosted("apt-hosted", "bionic", pgpPrivateKey, "abracadabra", "default", WritePolicy.ALLOW_ONCE, true) + + // create a npm repository backed by the default blob store. repository.createNpmHosted("npm-hosted", "default", true, WritePolicy.ALLOW_ONCE) // create a npm proxy repository backed by the default blob store. diff --git a/provision/use-apt-repository.sh b/provision/use-apt-repository.sh new file mode 100644 index 0000000..de6b592 --- /dev/null +++ b/provision/use-apt-repository.sh @@ -0,0 +1,38 @@ +#!/bin/bash +set -eux + +nexus_domain=$(hostname --fqdn) + +cd /vagrant/hello-world-debian-package + +# +# test the apt repository. + +# create the hello-world package. +# see https://www.debian.org/doc/manuals/debmake-doc/ch04.en.html +# see https://www.debian.org/doc/debian-policy/ch-source.html +# see apt-get source dash +apt-get install -y devscripts debmake debhelper dpkg-dev +pushd hello-world +debuild -i -us -uc -b +popd + +# upload. +# see https://help.sonatype.com/repomanager3/formats/apt-repositories +apt-get install -y curl +curl \ + --user 'alice.doe:password' \ + --header 'Content-Type: multipart/form-data' \ + --data-binary @hello-world_1.0.0_amd64.deb \ + https://$nexus_domain/repository/apt-hosted/ + +# trust the apt-hosted key. +apt-key add /vagrant/shared/apt-hosted-public.key + +# install the hello-world package. +echo "deb [arch=amd64] https://$nexus_domain/repository/apt-hosted bionic main" >/etc/apt/sources.list.d/nexus-apt-hosted.list +apt-get update +apt-get install -y hello-world +apt-cache show hello-world +apt-cache policy hello-world +hello-world