danboid / ALEZ

Arch Linux Easy ZFS installer
GNU General Public License v3.0
145 stars 25 forks source link

Auto-build ISO releases with Docker and Travis CI #20

Closed johnramsden closed 5 years ago

johnramsden commented 5 years ago

Automated releases using Travis CI

This pull request implements a Dockerfile and .travis.yml for auto-building releases, and deploying them on pushes to master.

The Dockerfile sets up an Arch Linux container with everything required to build an ISO. It has alez-downloader.sh, and the motd embedded in the ISO.

Container

The container can be built with:

docker build -t "alezbuild" ./

To run the container and build the ISO:

docker run --privileged \
        --volume="/dev:/dev" \
        --volume="$PWD/out:/opt/alez/iso/out" "alezbuild"

Both --privileged, and mounting /dev are necessary in order for the container to be able to chroot, and mount a loop-back device.

This can also be used as an easy way to create an ISO, and it doesn't require an arch system. This could be useful for users who are not currently using Arch but would like to create their own ISO.

All the same problems may occur that we have experienced before during the build if the kernel version and zfs version are out of sync.

Travis CI

The .travis.yml mainifest basically does does the above build and run of the container, saving the built ISO to out/, and if successful deploying as a new release.

In the current configuration it auto-tags a release in the form:

TRAVIS_TAG:-$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)

This could be modified to only create a release on tagged commits alternatively.

The configuration could be modified to only create a release on tagged commits alternatively. draft: true could also be used so that the releases are 'internal' to contributors, and releases could be modified before finalized.

The releases are tagged using the committers name and email with:

git config --local user.name "$(git log -1 $TRAVIS_COMMIT --pretty="%aN")"
git config --local user.email "$(git log -1 $TRAVIS_COMMIT --pretty="%cE")"

Alternatively the variables could be set to a specific user and email.

For authentication an OAuth key should be created with the 'repo' scope so it can push releases to the repo.

After logging in to Travis CI, and creating the token it can be encrypted using the Travis CI gem.

Encrypt it with:

travis login
travis encrypt "<TOKEN GOES HERE>"

The token can then be set in the .travis.yml under:

deploy:
provider: releases
api_key:
    secure: "<ENCRYPTED TOKEN GOES HERE>"

At this point, if Travis CI is enabled on the repo, pushes should auto build.

Tests

I've tested auto building and deploying a release on a test github repo. I downloaded the built ISO, and everything is working correctly as far as I could tell.