Verified Commit 2cbbe5a7 authored by Sven-Hendrik Haase's avatar Sven-Hendrik Haase
Browse files

Deduplicate a lot of code

parent 3f2721cb
Pipeline #2221 failed with stages
in 35 seconds
*~ build
*.orig output
/.idea
/base.tar*
/base-devel.tar*
rootfs/etc/pacman.conf
Dockerfile.base
Dockerfile.base-devel
DOCKER_USER:=pierres BUILDDIR=$(shell pwd)/build
BUILDDIR=build OUTPUTDIR=$(shell pwd)/output
PWD=$(shell pwd)
.PHONY: hooks define rootfs
hooks: mkdir -vp $(BUILDDIR)/alpm-hooks/usr/share/libalpm/hooks
mkdir -p alpm-hooks/usr/share/libalpm/hooks find /usr/share/libalpm/hooks -exec ln -sf /dev/null $(BUILDDIR)/alpm-hooks{} \;
find /usr/share/libalpm/hooks -exec ln -sf /dev/null $(PWD)/alpm-hooks{} \;
.PHONY: rootfs-base mkdir -vp $(BUILDDIR)/var/lib/pacman/ $(OUTPUTDIR)
rootfs-base: hooks install -Dm644 /usr/share/devtools/pacman-extra.conf $(BUILDDIR)/etc/pacman.conf
mkdir -vp $(BUILDDIR)/var/lib/pacman/ cat pacman-conf.d-noextract.conf >> $(BUILDDIR)/etc/pacman.conf
cp /usr/share/devtools/pacman-extra.conf rootfs/etc/pacman.conf
cat pacman-conf.d-noextract.conf >> rootfs/etc/pacman.conf
fakechroot -- fakeroot -- pacman -Sy -r $(BUILDDIR) \ fakechroot -- fakeroot -- pacman -Sy -r $(BUILDDIR) \
--noconfirm --dbpath $(PWD)/$(BUILDDIR)/var/lib/pacman \ --noconfirm --dbpath $(BUILDDIR)/var/lib/pacman \
--config rootfs/etc/pacman.conf \ --config $(BUILDDIR)/etc/pacman.conf \
--noscriptlet \ --noscriptlet \
--hookdir $(PWD)/alpm-hooks/usr/share/libalpm/hooks/ base --hookdir $(BUILDDIR)/alpm-hooks/usr/share/libalpm/hooks/ $(2)
cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* $(BUILDDIR)/ cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* $(BUILDDIR)/
# remove passwordless login for root (see CVE-2019-5021 for reference) # remove passwordless login for root (see CVE-2019-5021 for reference)
...@@ -24,65 +20,38 @@ rootfs-base: hooks ...@@ -24,65 +20,38 @@ rootfs-base: hooks
# fakeroot to map the gid/uid of the builder process to root # fakeroot to map the gid/uid of the builder process to root
# fixes #22 # fixes #22
fakeroot -- tar --numeric-owner --xattrs --acls --exclude-from=exclude -C $(BUILDDIR) -c . -f base.tar fakeroot -- tar --numeric-owner --xattrs --acls --exclude-from=exclude -C $(BUILDDIR) -c . -f $(OUTPUTDIR)/$(1).tar
rm -rf $(BUILDDIR) alpm-hooks
.PHONY: rootfs-base-devel cd $(OUTPUTDIR); xz -9 -T0 -f $(1).tar; sha256sum $(1).tar.xz > $(1).tar.xz.SHA256
rootfs-base-devel: hooks endef
mkdir -vp $(BUILDDIR)/var/lib/pacman/
cp /usr/share/devtools/pacman-extra.conf rootfs/etc/pacman.conf
cat pacman-conf.d-noextract.conf >> rootfs/etc/pacman.conf
fakechroot -- fakeroot -- pacman -Sy -r $(BUILDDIR) \
--noconfirm --dbpath $(PWD)/$(BUILDDIR)/var/lib/pacman \
--config rootfs/etc/pacman.conf \
--noscriptlet \
--hookdir $(PWD)/alpm-hooks/usr/share/libalpm/hooks/ base base-devel
cp --recursive --preserve=timestamps --backup --suffix=.pacnew rootfs/* $(BUILDDIR)/
# remove passwordless login for root (see CVE-2019-5021 for reference) define dockerfile
sed -i -e 's/^root::/root:!:/' "$(BUILDDIR)/etc/shadow" sed -e "s|TEMPLATE_ROOTFS_FILE|$(1).tar.xz|" \
-e "s|TEMPLATE_ROOTFS_URL|file:///$(1).tar.xz|" \
-e "s|TEMPLATE_ROOTFS_HASH|$$(cat $(OUTPUTDIR)/$(1).tar.xz.SHA256)|" \
Dockerfile.template > $(OUTPUTDIR)/Dockerfile.$(1)
endef
# fakeroot to map the gid/uid of the builder process to root .PHONY: clean
# fixes #22 clean:
fakeroot -- tar --numeric-owner --xattrs --acls --exclude-from=exclude -C $(BUILDDIR) -c . -f base-devel.tar rm -rf $(BUILDDIR) $(OUTPUTDIR)
rm -rf $(BUILDDIR) alpm-hooks
base.tar.xz: rootfs-base $(OUTPUTDIR)/base.tar.xz:
xz -9 -T0 -f base.tar $(call rootfs,base,base)
sha256sum base.tar.xz > base.tar.xz.SHA256
base-devel.tar.xz: rootfs-base-devel $(OUTPUTDIR)/base-devel.tar.xz:
xz -9 -T0 -f base-devel.tar $(call rootfs,base,base base-devel)
sha256sum base-devel.tar.xz > base-devel.tar.xz.SHA256
.PHONY: dockerfile-image-base $(OUTPUTDIR)/Dockerfile.base:
dockerfile-image-base: base.tar.xz $(call dockerfile,base)
sed -e "s/TEMPLATE_ROOTFS_FILE/base.tar.xz/" \
-e "s/TEMPLATE_ROOTFS_URL/file:\/\/\/base.tar.xz/" \
-e "s/TEMPLATE_ROOTFS_HASH/$$(cat base.tar.xz.SHA256)/" \
Dockerfile.template > Dockerfile.base
.PHONY: dockerfile-image-base-devel $(OUTPUTDIR)/Dockerfile.base-devel:
dockerfile-image-base-devel: base-devel.tar.xz $(call dockerfile,base-devel)
sed -e "s/TEMPLATE_ROOTFS_FILE/base-devel.tar.xz/" \
-e "s/TEMPLATE_ROOTFS_URL/file:\/\/\/base-devel.tar.xz/" \
-e "s/TEMPLATE_ROOTFS_HASH/$$(cat base-devel.tar.xz.SHA256)/" \
Dockerfile.template > Dockerfile.base-devel
.PHONY: docker-image-base .PHONY: docker-image-base
docker-image-base: dockerfile-image-base image-base: $(OUTPUTDIR)/base.tar.xz $(OUTPUTDIR)/Dockerfile.base
docker build -f Dockerfile.base -t archlinux/archlinux:base . docker build -f $(OUTPUTDIR)/Dockerfile.base -t archlinux/archlinux:base $(OUTPUTDIR)
.PHONY: docker-image-base-devel .PHONY: docker-image-base-devel
docker-image-base-devel: dockerfile-image-base-devel image-base-devel: $(OUTPUTDIR)/base-devel.tar.xz $(OUTPUTDIR)/Dockerfile.base-devel
docker build -f Dockerfile.base-devel -t archlinux/archlinux:base-devel . docker build -f $(OUTPUTDIR)/Dockerfile.base-devel -t archlinux/archlinux:base-devel $(OUTPUTDIR)
.PHONY: docker-push-base
docker-push-base:
docker login -u $(DOCKER_USER)
docker push archlinux/archlinux:base
.PHONY: docker-push-base-devel
docker-push-base-devel:
docker login -u $(DOCKER_USER)
docker push archlinux/archlinux:base-devel
...@@ -15,3 +15,4 @@ ...@@ -15,3 +15,4 @@
./var/cache/pacman/pkg/* ./var/cache/pacman/pkg/*
./var/lib/pacman/sync/* ./var/lib/pacman/sync/*
./var/tmp/* ./var/tmp/*
./alpm-hooks
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment