-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from resnullius/feature/v2
v2: make it more easy to use!
- Loading branch information
Showing
5 changed files
with
174 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,21 @@ alpine-devel-howto | |
|
||
WHAT IS THIS? | ||
------------- | ||
This is the way to build alpinelinux packages using docker containers. This is | ||
an example, is should be taken as a base and the `build.bash.base` be modified | ||
according to your needs and put on your `~/bin/` or `/usr/local/bin/`. | ||
This is my way to build alpinelinux packages using docker containers. | ||
|
||
The docker containers that uses is `resnullius/alpine-devel` and the tags | ||
available are `3.2`, `3.3` and `edge`. It can be used with | ||
`resnullius/alpine-devel-armv7l` as well (it has the same tags), you just need | ||
to change the docker image's name. | ||
I use the bash script `alpine-pkg-build` to generate my keys, build packages and | ||
run into a shell in them. | ||
|
||
There is a script for helping you figure out how to create your developer keys | ||
called `createkeys.bash`. | ||
Just clone this repo and make a symbolic link to your `~/bin/` or | ||
`/usr/local/bin/` and you should be ready to go. | ||
|
||
This is supposed to be used together with | ||
[docker-alpine-devel](https:/resnullius/docker-alpine-devel) and at | ||
the moment only works for `x86_64`. It supports alpine versions: 3.2, 3.3 and | ||
edge. | ||
|
||
It expects you to have a `~/.alpine` directory with subdirectories `keys` and | ||
`conf`. | ||
`conf`. You can change this with arguments to the script. | ||
|
||
UPDATE THE ABUILD.CONF | ||
---------------------- | ||
|
@@ -27,11 +28,13 @@ you are not building for the architecture `x86_64`. Remember to add it into your | |
|
||
GENERATING YOUR KEYS | ||
-------------------- | ||
**You just need to do this once.** | ||
|
||
After saving your `abuild.conf` into `~/.alpine/conf/` and created | ||
`~/.alpine/keys` you can run `bash createkeys.bash` from this repo, the output | ||
should be something like: | ||
`~/.alpine/keys` you can run `bash alpine-build-pkg gen-key` from this repo, | ||
the output should be something like: | ||
|
||
$ bash createkeys.bash | ||
$ bash alpine-build-pkg gen-key | ||
Generating RSA private key, 2048 bit long modulus | ||
....................+++ | ||
................................................................+++ | ||
|
@@ -59,27 +62,41 @@ sign with those all your packages. | |
Add the line that starts with `PACKAGER_PRIVKEY` to your `abuild.conf`, the one | ||
you just saved into `~/.alpine/conf/abuild.conf`. | ||
|
||
You can change where the keys are saved with the `-k` argument, so doing `bash | ||
alpine-build-pkg gen-key -k .` would save the keys in your `$PWD`. The other | ||
argument that accepts is `-c` to tell where should look for the `abuild.conf` | ||
file. See more with `alpine-build-pkg --help`. | ||
|
||
**You just need to do this once.** | ||
|
||
BUILDING A PACKAGE | ||
------------------ | ||
Go to the directory where your `APKBUILD` lives and run the script you renamed | ||
from `build.bash.base`, in my case is called `alpine-pkg-build` on my `~/bin/` | ||
so just: | ||
Go to the directory where your `APKBUILD` lives and run the `alpine-build-pkg`. | ||
|
||
$ alpine-pkg-build | ||
|
||
That will create a `pkgs/` directory in your `$PWD` and inside you will have a | ||
folder with the name of your architecture and inside there will be an | ||
`APKINDEX.tar.gz` and the `.apk`s created by your `APKBUILD`. | ||
|
||
There are more options for building, just keep reading other titles. | ||
Right now, it defaults to build things with alpine's version 3.3, which is the | ||
current stable, but you can change it to 3.2 or edge by using the `-v` flag | ||
like this: | ||
|
||
$ alpine-build-pkg -v edge | ||
|
||
There are more options for building, just keep reading other titles and check | ||
out what's in `alpine-build-pkg --help`. | ||
|
||
RUNNING THE CONTAINER | ||
--------------------- | ||
There's an extra `run.bash` script that just mounts everything for you and | ||
leaves you in a `sh` shell inside the container so you can test things out | ||
there. | ||
There's an extra option on `alpine-build-pkg`, maybe you want to get into the | ||
container and run `entrypoint.sh` by yourself or do other stuff there, you can | ||
get into it's shell by running: | ||
|
||
$ alpine-build-pkg run | ||
|
||
It accepts arguments as well. See which ones with `alpine-build-pkg --help`. | ||
|
||
PLAYING WITH THE OPTIONS ON THE BUILD AND RUN SCRIPTS | ||
----------------------------------------------------- | ||
|
@@ -96,9 +113,9 @@ And inside each directory there's an `APKBUILD`, so you would end up doing | |
something like this to get it built correctly: | ||
|
||
$ cd libtorrent/ | ||
$ REPO_DIR=~/build/repo alpine-pkg-build | ||
$ alpine-build-pkg -r ../repo | ||
$ cd ../rtorrent/ | ||
$ REPO_DIR=~/build/repo alpine-pkg-build | ||
$ alpine-pkg-build -r ~/build/repo | ||
|
||
Since they both shared the same repository directory `rtorrent` was able to use | ||
the `libtorrent-dev.apk` you just build and it will even have a | ||
|
@@ -112,6 +129,10 @@ PS: Remember, if they don't have your `.rsa.pub` key in their `/etc/apk/keys` | |
they will need to make `apk add --allow-untrusted rtorrent` in order to actually | ||
be able to install the package you built. | ||
|
||
PS2: Did you saw `-r` supports relative paths? Yes, it does! And all the path | ||
arguments too. Check what other options are available with `alpine-build-pkg | ||
--help`. | ||
|
||
AUTHOR AND LICENSE | ||
------------------ | ||
© 2016, Jose-Luis Rivas `<[email protected]>`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/usr/bin/env bash | ||
|
||
declare help=" | ||
Script for building alpine pkgs using resnullius/alpine-devel docker's images. | ||
Usage: | ||
alpine-build-pkg run [-v <version>] [-r <path>] [-c <path>] [-k <path>] | ||
alpine-build-pkg gen-key [-c <path>] [-k <path>] | ||
alpine-build-pkg [-v 3.3] [-r <path>] [-c <path>] [-k <path>] [-s <path>] \ | ||
[-e cmd] | ||
alpine-build-pkg --version | ||
alpine-build-pkg -h | --help | ||
Options: | ||
-v Alpine tag to use, defaults to 3.3. | ||
-r Path to repo, final destination of the package | ||
being built and used as extra repo during the | ||
build process. | ||
-c Path to the abuild.conf file, defaults to | ||
~/.alpine/conf. | ||
-k Path to the developer keys, defaults to | ||
~/.alpine/keys. | ||
-s Path to the source, defaults to current | ||
directory. | ||
-e Change the entrypoint to that value. | ||
-h --help Show this screen. | ||
--version Show versions. | ||
" | ||
declare version=" | ||
Version: 2.0.0. | ||
Licensed under the MIT terms. | ||
" | ||
|
||
declare keys_dir=${KEYS_DIR:-~/.alpine/keys} | ||
declare conf_dir=${CONF_DIR:-~/.alpine/conf} | ||
declare repo_dir=${REPO_DIR:-$PWD/pkgs} | ||
declare src_dir=${SRC_DIR:-$PWD} | ||
[ -d "$repo_dir" ] && repo_dir=$(cd "$repo_dir" && pwd) | ||
[ -d "$src_dir" ] && src_dir=$(cd "$src_dir" && pwd) | ||
|
||
declare image_ver="3.3" | ||
declare entrypoint | ||
|
||
evaluate_build_options() { | ||
while test -n "$1"; do | ||
case "$1" in | ||
-v) | ||
image_ver="$2"; shift; shift;; | ||
-r) | ||
[[ -d "$2" ]] && repo_dir=$(cd "$2" && pwd); | ||
shift; shift;; | ||
-c) | ||
[[ -d "$2" ]] && conf_dir=$(cd "$2" && pwd); | ||
shift; shift;; | ||
-k) | ||
[[ -d "$2" ]] && keys_dir=$(cd "$2" && pwd); | ||
shift; shift;; | ||
-s) | ||
[[ -d "$2" ]] && src_dir=$(cd "$2" && pwd); | ||
shift; shift;; | ||
-e) | ||
entrypoint="--entrypoint $2" | ||
if [[ "$2" == "/bin/sh" ]]; then | ||
entrypoint+=" -ti" | ||
fi | ||
shift; shift;; | ||
*) shift;; | ||
esac | ||
done | ||
echo "Will build using:" | ||
echo "Alpine version: $image_ver" | ||
echo "Repo dir: $repo_dir" | ||
echo "Config dir: $conf_dir" | ||
echo "Keys dir: $keys_dir" | ||
echo "Source dir: $src_dir" | ||
if [[ -n "$entrypoint" ]]; then | ||
echo "Entrypoint changed to $entrypoint" | ||
fi | ||
} | ||
|
||
basic_check() { | ||
echo "Basic checks" | ||
[[ ! -e "$src_dir"/APKBUILD ]] && \ | ||
[[ "$entrypoint" != "--entrypoint genkey.sh" ]] && \ | ||
echo "No APKBUILD on $src_dir" && exit 1 | ||
echo "Everything in place" | ||
} | ||
|
||
# shellcheck disable=SC2086 | ||
run_docker() { | ||
docker run \ | ||
$entrypoint \ | ||
--rm \ | ||
-v "$src_dir":/opt/src \ | ||
-v "$repo_dir":/opt/repo \ | ||
-v "$conf_dir":/opt/conf \ | ||
-v "$keys_dir":/opt/keys \ | ||
resnullius/alpine-devel:"$image_ver" | ||
} | ||
|
||
build() { | ||
evaluate_build_options "$@" | ||
basic_check | ||
run_docker | ||
} | ||
|
||
print_version() { | ||
echo "$version" | ||
} | ||
|
||
print_help() { | ||
echo "$help" | ||
} | ||
|
||
main() { | ||
set -eo pipefail; [[ "$TRACE" ]] && set -x | ||
declare cmd="$1" | ||
case "$cmd" in | ||
-h|--help) shift; print_help "$@";; | ||
--version) shift; print_version "$@";; | ||
run) shift; | ||
set - "$@" "-e" "/bin/sh" | ||
build "$@";; | ||
gen-key) shift; | ||
set - "$@" "-e" "genkey.sh" | ||
build "$@";; | ||
*) build "$@";; | ||
esac | ||
} | ||
|
||
main "$@" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.