aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Buchholz <tomalok@gmail.com>2018-09-07 08:15:19 -0700
committerMike Crute <crutem@amazon.com>2018-09-11 09:57:37 -0700
commit86596057321716b77b1a38098e730284dd962822 (patch)
treec4850832cfff0546f12ceb51bba7f4241bcbe8b3
parent4065c4ebb316dab2e9f66b5e3f903e0548271266 (diff)
downloadalpine-ec2-ami-86596057321716b77b1a38098e730284dd962822.tar.bz2
alpine-ec2-ami-86596057321716b77b1a38098e730284dd962822.tar.xz
alpine-ec2-ami-86596057321716b77b1a38098e730284dd962822.zip
make edge
* Add the ability to 'make edge' to create an AMI based on the latest Alpine edge repository * Force 'ami_revision' to be 'rYYYYMMDDHHSS'
-rw-r--r--Makefile11
-rw-r--r--alpine-ami.yaml9
-rwxr-xr-xmake_ami.sh21
3 files changed, 33 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index d2505b2..3f08dd0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,16 @@
1.PHONY: ami 1.PHONY: ami
2ami: build/convert 2
3ami: convert
4 packer build -var-file=build/variables.json build/alpine-ami.json
5
6edge: convert
7 @echo '{ "alpine_release": "edge", "ami_release": "'`date +%Y%m%d%H%M%S`'" }' > build/edge.json
8 packer build -var-file=build/variables.json -var-file=build/edge.json build/alpine-ami.json
9
10convert: build/convert
3 [ -f variables.yaml ] || cp variables.yaml-default variables.yaml 11 [ -f variables.yaml ] || cp variables.yaml-default variables.yaml
4 build/convert variables.yaml > build/variables.json 12 build/convert variables.yaml > build/variables.json
5 build/convert alpine-ami.yaml > build/alpine-ami.json 13 build/convert alpine-ami.yaml > build/alpine-ami.json
6 packer build -var-file=build/variables.json build/alpine-ami.json
7 14
8build/convert: 15build/convert:
9 [ -d ".py3" ] || python3 -m venv .py3 16 [ -d ".py3" ] || python3 -m venv .py3
diff --git a/alpine-ami.yaml b/alpine-ami.yaml
index 0ec2e21..8baabc0 100644
--- a/alpine-ami.yaml
+++ b/alpine-ami.yaml
@@ -1,10 +1,9 @@
1variables: 1variables:
2 2
3 # NOTE: Configuration is done with a `variables.yaml` file. If it doesn't 3 # NOTE: Configuration is done with a 'variables.yaml' file. If it doesn't
4 # exist, default configuration is copied from `variables.yaml-default`. 4 # exist, default configuration is copied from 'variables.yaml-default'.
5 5
6 # NOTE: Changing alpine_release requires modifying `make_ami.sh` -- don't 6 # NOTE: Changing alpine_release may require modifying 'make_ami.sh'.
7 # override this in `variables.json`!
8 alpine_release: "3.8" 7 alpine_release: "3.8"
9 8
10 9
@@ -55,4 +54,6 @@ builders:
55provisioners: 54provisioners:
56 - type: "shell" 55 - type: "shell"
57 script: "make_ami.sh" 56 script: "make_ami.sh"
57 environment_vars:
58 - "ALPINE_RELEASE={{user `alpine_release`}}"
58 execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}''"' 59 execute_command: 'sudo sh -c "{{ .Vars }} {{ .Path }} ''{{user `add_repos`}}'' ''{{user `add_pkgs`}}''"'
diff --git a/make_ami.sh b/make_ami.sh
index 0d10058..9b24227 100755
--- a/make_ami.sh
+++ b/make_ami.sh
@@ -3,12 +3,14 @@
3 3
4set -eu 4set -eu
5 5
6: ${ALPINE_RELEASE:="3.8"} # not tested against edge 6: ${MIN_RELEASE:="3.8"}
7: ${APK_TOOLS_URI:="https://github.com/alpinelinux/apk-tools/releases/download/v2.10.0/apk-tools-2.10.0-x86_64-linux.tar.gz"} 7: ${APK_TOOLS_URI:="https://github.com/alpinelinux/apk-tools/releases/download/v2.10.0/apk-tools-2.10.0-x86_64-linux.tar.gz"}
8: ${APK_TOOLS_SHA256:="77f2d256fcd5d6fdafadf43bb6a9c85c3da7bb471ee842dcd729175235cb9fed"} 8: ${APK_TOOLS_SHA256:="77f2d256fcd5d6fdafadf43bb6a9c85c3da7bb471ee842dcd729175235cb9fed"}
9: ${ALPINE_KEYS:="http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/alpine-keys-2.1-r1.apk"} 9: ${ALPINE_KEYS:="http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/alpine-keys-2.1-r1.apk"}
10: ${ALPINE_KEYS_SHA256:="f7832b848cedca482b145011cf516e82392f02a10713875cb09f39c7221c6f17"} 10: ${ALPINE_KEYS_SHA256:="f7832b848cedca482b145011cf516e82392f02a10713875cb09f39c7221c6f17"}
11 11
12: ${ALPINE_RELEASE:="${MIN_RELEASE}"} # unless otherwise specified
13
12die() { 14die() {
13 printf '\033[1;31mERROR:\033[0m %s\n' "$@" >&2 # bold red 15 printf '\033[1;31mERROR:\033[0m %s\n' "$@" >&2 # bold red
14 exit 1 16 exit 1
@@ -75,13 +77,26 @@ setup_repositories() {
75 local add_repos="$2" # extra repo lines, comma separated 77 local add_repos="$2" # extra repo lines, comma separated
76 78
77 mkdir -p "$target"/etc/apk/keys 79 mkdir -p "$target"/etc/apk/keys
78 cat > "$target"/etc/apk/repositories <<EOF 80
81 if [ "$ALPINE_RELEASE" = 'edge' ]; then
82 cat > "$target"/etc/apk/repositories <<EOF
83http://dl-cdn.alpinelinux.org/alpine/edge/main
84http://dl-cdn.alpinelinux.org/alpine/edge/community
85http://dl-cdn.alpinelinux.org/alpine/edge/testing
86EOF
87 else
88 cat > "$target"/etc/apk/repositories <<EOF
79http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/main 89http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/main
80http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/community 90http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_RELEASE/community
91EOF
92 fi
93 # NOTE: until several key packages graduate from edge...
94 cat >> "$target"/etc/apk/repositories <<EOF
81@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main 95@edge-main http://dl-cdn.alpinelinux.org/alpine/edge/main
82@edge-community http://dl-cdn.alpinelinux.org/alpine/edge/community 96@edge-community http://dl-cdn.alpinelinux.org/alpine/edge/community
83@edge-testing http://dl-cdn.alpinelinux.org/alpine/edge/testing 97@edge-testing http://dl-cdn.alpinelinux.org/alpine/edge/testing
84EOF 98EOF
99
85 echo "$add_repos" | tr , "\012" >> "$target"/etc/apk/repositories 100 echo "$add_repos" | tr , "\012" >> "$target"/etc/apk/repositories
86} 101}
87 102
@@ -269,6 +284,8 @@ cleanup() {
269 284
270main() { 285main() {
271 [ "$#" -ne 2 ] && { echo "usage: $0 '<repo>[,<repo>]' '<pkg>[,<pkg>]'"; exit 1; } 286 [ "$#" -ne 2 ] && { echo "usage: $0 '<repo>[,<repo>]' '<pkg>[,<pkg>]'"; exit 1; }
287 [ "$ALPINE_RELEASE" != 'edge' ] && [[ "$ALPINE_RELEASE" -lt "$MIN_RELEASE" ]] && \
288 { echo "ERR: minimum alpine_release value must be '$MIN_RELEASE'"; exit 1; }
272 289
273 local add_repos="$1" 290 local add_repos="$1"
274 local add_pkgs="$2" 291 local add_pkgs="$2"