diff --git a/87_apk/.gitignore b/87_apk/.gitignore new file mode 100644 index 0000000..3fa7ece --- /dev/null +++ b/87_apk/.gitignore @@ -0,0 +1,2 @@ +*.apk +*.gz diff --git a/87_apk/Dockerfile.build b/87_apk/Dockerfile.build new file mode 100644 index 0000000..fa5a61e --- /dev/null +++ b/87_apk/Dockerfile.build @@ -0,0 +1,27 @@ +FROM alpine:3.20.0 AS build + +RUN apk update && apk add --no-cache mandoc man-pages abuild curl doas alpine-sdk + +ENV USERNAME="builder" +ENV GROUP="builder" + +# Create a non-admin user and group +RUN addgroup -S $USERNAME && adduser -S $USERNAME -G $GROUP +RUN echo "$USERNAME:$USERNAME" | chpasswd +RUN echo "$USERNAME ALL=(ALL) ALL" > /etc/sudoers +RUN echo 'GROUP="$GROUP"' > /etc/abuild.conf + +WORKDIR /package + +# Copy files from the local machine to the container +COPY ./hello-world /package + +# Change the ownership of the working directory to the non-admin user +RUN chown -R builder:builder /package + +# Switch to the non-admin user +USER builder + +WORKDIR /package + +#abuild-keygen -a -i diff --git a/87_apk/README.md b/87_apk/README.md new file mode 100644 index 0000000..90fdcac --- /dev/null +++ b/87_apk/README.md @@ -0,0 +1,27 @@ +# APK + +TODO: + +- Create packages +- Host packages in a repository (s3) + +## Build + +Build and run the container + +```sh +# Build +docker build -t apkbuilder -f Dockerfile.build . + +# run +docker run -it --entrypoint /bin/sh apkbuilder +``` + +## Resources + +- Alpine linux create a apk-package [here](https://stackoverflow.com/questions/59684341/alpine-linux-create-a-apk-package) +- https://github.com/alpinelinux +- https://github.com/alpinelinux/apk-tools/blob/master/doc/apk.8.scd +- https://github.com/gr0und-s3ct0r/apkbuild +https://codeberg.org/chimo/apkbuilds +- https://wiki.alpinelinux.org/wiki/Abuild_and_Helpers diff --git a/87_apk/hello-world/APKBUILD b/87_apk/hello-world/APKBUILD new file mode 100644 index 0000000..5223ef3 --- /dev/null +++ b/87_apk/hello-world/APKBUILD @@ -0,0 +1,35 @@ +# Contributor: +# Maintainer: +pkgname=hello-world +pkgver=1.0 +pkgrel=0 +pkgdesc="Hello World! program" +url="http://alpinelinux.org" +arch="noarch" +license="GPL" +depends= +makedepends= +install= +subpackages= +source="" +builddir="$srcdir/$pkgname-$pkgver" + +# append extra dependencies to -dev subpackage +# remove if not used. +# depends_dev="somepackage-dev" + +prepare() { + mkdir -p "$builddir" +} + +build() { + cd "$builddir" + cp ../hello-world.sh . +} + +package() { + cd "$builddir" + install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname +} + +sha512sums="" #generate with 'abuild checksum' diff --git a/87_apk/hello-world/hello-world.sh b/87_apk/hello-world/hello-world.sh new file mode 100755 index 0000000..daf152a --- /dev/null +++ b/87_apk/hello-world/hello-world.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -euf -o pipefail + +readonly SCRIPT_NAME=$(basename "$0") +readonly SCRIPT_PATH=${0} +readonly SCRIPT_DIR=$(dirname "$SCRIPT_PATH") +readonly HOME_DIR=~ +if [[ $(command -v greadlink) ]]; then + # mac requires 'brew install coreutils' + readonly SCRIPT_FULL_PATH="$(dirname "$(greadlink -f "$0")")" +else + readonly SCRIPT_FULL_PATH="$(dirname "$(readlink -f "$0")")" +fi + +echo "************************************************" +echo "* hello-world from debian package" +echo "************************************************" +echo "SCRIPT_NAME=${SCRIPT_NAME}" +echo "SCRIPT_PATH=${SCRIPT_PATH}" +echo "SCRIPT_DIR=${SCRIPT_DIR}" +echo "HOME_DIR=${HOME_DIR}" +echo "SCRIPT_FULL_PATH=${SCRIPT_FULL_PATH}" +echo "************************************************" +