Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ef03350394e3c0670c2ba6d8a7495e21fcf790b9
Author: Tatsuya Kitagawa <tatsuya.kitagawa@t13a.com>
Date:   Sun May 31 18:12:03 2020 +0900

    Update README.md

commit 6b6e190e695340095b79d688a5b0d8165eeba423
Author: Tatsuya Kitagawa <tatsuya.kitagawa@t13a.com>
Date:   Sun May 31 18:11:56 2020 +0900

    Move script

commit f17fc0667d63f465d84201411b0e73c33c5f9881
Author: Tatsuya Kitagawa <tatsuya.kitagawa@t13a.com>
Date:   Sun Oct 27 15:10:07 2019 +0900

    Add fetch script
  • Loading branch information
t13a committed May 31, 2020
1 parent 1b10146 commit 885baa9
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 40 deletions.
58 changes: 18 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,17 @@ An [Arch Linux](https://www.archlinux.org) cloud installation image.
- Auto login disabled
- Root password locked

The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run entirely on the Docker container. Therefore, it can be easily integrated with modern CI tools.

## Prerequisites

- Docker
- GNU Make
- KVM enabled Linux (optional but strongly recommended)

## Getting started
## Get the latest release

### Build and test the ISO image
You can download the latest and past releases from [GitHub releases](https://github.com/t13a/archlinux-cloud/releases).

The following command generates the ISO image at `out/iso/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests.
Alternatively, if you have `bash`, `curl` and `jq` installed on your computer, you can get the latest release with the following command.

```sh
$ make init build test # or just simply `make`
$ curl -fsSL https://raw.githubusercontent.com/t13a/archlinux-cloud/master/get-archlinux-cloud.sh | sh
```

To delete all generated files, run the following command.

```sh
$ make clean
```

### Boot with cloud-init
## Boot with cloud-init

Please refer to the [official documentation](https://cloudinit.readthedocs.io/) for a general explanation.

Expand All @@ -60,35 +46,27 @@ bootcmd:

## Development

### Build the ISO image step-by-step
The build process and E2E tests (using [QEMU](https://www.qemu.org/)) are run entirely on the Docker container. Therefore, it can be easily integrated with modern CI tools.

```sh
$ make init
$ make build/exec
[build@xxxxxxxxxxxx build]$ make profile
[build@xxxxxxxxxxxx build]$ make repo
[build@xxxxxxxxxxxx build]$ make iso
[build@xxxxxxxxxxxx build]$ exit
```
### Prerequisites

### Run QEMU with the ISO image
- Bash
- Docker
- GNU Make
- KVM enabled Linux (optional but strongly recommended)

### Build and test the ISO image

The following command generates the ISO image at `out/archlinux-cloud-YYYY.mm.dd-x86_64.iso` then run all E2E tests.

```sh
$ make test/exec
[test@xxxxxxxxxxxx test]$ make ssh-key
[test@xxxxxxxxxxxx test]$ make cidata
[test@xxxxxxxxxxxx test]$ qemu-daemon
[test@xxxxxxxxxxxx test]$ qemu-serial
[test@xxxxxxxxxxxx test]$ qemu-kill
$ make init build test # or just simply `make`
```

or
To delete all generated files, run the following command.

```sh
$ make test/exec
[test@xxxxxxxxxxxx test]$ make ssh-key
[test@xxxxxxxxxxxx test]$ make cidata
[test@xxxxxxxxxxxx test]$ qemu-daemon -f # start in foreground
$ make clean
```

## References
Expand Down
168 changes: 168 additions & 0 deletions get-archlinux-cloud.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env bash

set -euo pipefail

function cmd_iso() {
echo 'Fetching ISO...' >&2

local url="$(cmd_iso_url)"

if [ "${OUTPUT}" == - ]
then
run_or_dryrun curl -L "${url}"
else
local output="${OUTPUT:-$(basename "${url}")}"
local part="${output}.part"

if [ -e "${output}" ]
then
echo "${output}: Already exists" >&2
exit 1
fi

run_or_dryrun curl -L "${url}" -o "${part}"
run_or_dryrun mv "${part}" "${output}"
fi
}

function cmd_iso_url() {
echo "https://github.com/${SOURCE}/releases/download/${TAG}/archlinux-cloud-${ISO_VERSION}-x86_64.iso"
}

function cmd_latest_iso_version() {
if [ -z "${ISO_VERSION}" ]
then
function func() {
curl -LSs "https://api.github.com/repos/${SOURCE}/releases/tags/${TAG}" \
| jq -r '.assets[] | .name' \
| grep -o '^archlinux-cloud-.*-x86_64\.iso$' \
| sed -e 's/^archlinux-cloud-//g' -e 's/-x86_64\.iso$//g' \
| sort \
| tail -n1
}

echo 'Fetching latest ISO version...' >&2

local ret

if ! ret="$(func)" || [ -z "${ret}" ]
then
echo 'Failed to get latest ISO version' >&2
return 1
fi

ISO_VERSION="${ret}"
fi

echo "${ISO_VERSION}"
}

function cmd_latest_tag() {
if [ -z "${TAG}" ]
then
function func() {
curl -LSs "https://api.github.com/repos/${SOURCE}/releases/latest" \
| jq -r '.tag_name'
}

echo 'Fetching latest tag...' >&2

local ret

if ! ret="$(func)" || [ "${ret}" == 'null' ]
then
echo 'Failed to get latest tag' >&2
return 1
fi

TAG="${ret}"
fi

echo "${TAG}"
}

function help() {
cat << EOF
${0} [OPTION]... [TARGET]
Options:
-h show help
-n dry run
-o OUTPUT specify output filename (default: basename of ISO)
-s SOURCE specify source repository (default: '${SOURCE}')
-t TAG specify tag (default: latest)
-v ISO_VERSION specify ISO version (default: latest)
Targets:
iso (default)
iso-url
latest-iso-version
latest-tag
EOF
}

function run_or_dryrun() {
if [ -z "${DRYRUN}" ]
then
"${@}"
else
echo '[DRYRUN]' "${@}" >&2
fi
}

DRYRUN=
ISO_VERSION=
OUTPUT=
SOURCE=t13a/archlinux-cloud
TAG=
TARGET=

while getopts hno:s:t:v: OPT
do
case "${OPT}" in
h)
help
exit 0
;;
n)
DRYRUN=yes
;;
o)
OUTPUT="${OPTARG}"
;;
s)
SOURCE="${OPTARG}"
;;
t)
TAG="${OPTARG}"
;;
v)
ISO_VERSION="${OPTARG}"
;;
*)
exit 1
;;
esac
done

shift $((${OPTIND} - 1))

if [ -z "${TAG}" ]
then
if ! TAG="$(cmd_latest_tag)"
then
exit 1
fi
fi

if [ -z "${ISO_VERSION}" ]
then
if ! ISO_VERSION="$(cmd_latest_iso_version)"
then
exit 1
fi
fi

TARGET="${1:-iso}"

"cmd_${TARGET//-/_}"

0 comments on commit 885baa9

Please sign in to comment.