Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

Commit 3f5368a

Browse files
committed
Initial acirepo command
Eventually this can become a go(?) program
1 parent 5df4287 commit 3f5368a

File tree

4 files changed

+272
-1
lines changed

4 files changed

+272
-1
lines changed

acirepo.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# acirepo tool
2+
3+
The acirepo tool manages ACI repositories from the command line.
4+
5+
## acirepo init
6+
7+
Creates a repository in an S3 bucket.
8+
9+
Example syntax:
10+
11+
```acirepo init s3://aci.mydomain.com```
12+
13+
Limitations:
14+
15+
* The bucket is presumed to already exist (use `aws s3 mb <bucketname>`)
16+
* The repository is made public, and a basic website configuration is enabled
17+
* S3 storage only
18+
19+
### acirepo push
20+
21+
Uploads an image into the ACI repo. The image name and version will be extracted from the metadata.
22+
23+
Example syntax:
24+
25+
```acirepo push java7/image.aci s3://aci.mydomain.com```
26+
27+
Limitations:
28+
29+
* Image will be made public
30+
* Repo should already exist (`acirepo init`)
31+
* Image will be automatically signed if not already signed

bin/acirepo

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ME=$0
6+
COMMAND=$1
7+
8+
function show-help() {
9+
echo "Valid commands:"
10+
echo " init"
11+
echo " push"
12+
}
13+
14+
function get_s3_bucket_location() {
15+
BUCKET=$1
16+
17+
echo "Locating S3 bucket ${BUCKET}..."
18+
local bucket_region=`aws --output text s3api get-bucket-location --bucket ${BUCKET}`
19+
local url_base=https://s3-${bucket_region}.amazonaws.com/${BUCKET}
20+
21+
# us-east-1 does not fit the pattern
22+
if [[ "${bucket_region}" == "None" ]]; then
23+
bucket_region="us-east-1"
24+
url_base=https://s3.amazonaws.com/${BUCKET}
25+
fi
26+
27+
S3_BUCKET_REGION=${bucket_region}
28+
S3_URL_BASE=${url_base}
29+
}
30+
31+
function command-init() {
32+
PREFIX=$1
33+
REPO=$2
34+
35+
if [[ -z "${PREFIX}" || -z "${REPO}" ]]; then
36+
echo "syntax: $ME init <prefix> <repo>"
37+
echo "For example, $ME init aci.mydomain.com s3://aci.mydomain.com"
38+
exit 1
39+
fi
40+
41+
if [[ "${REPO}" == s3://* ]]; then
42+
BUCKET=${REPO:5}
43+
44+
# TODO: Create bucket automatically?
45+
BUILD=.build
46+
mkdir -p ${BUILD}
47+
48+
if [[ ! -f ${BUILD}/pubkeys.gpg ]]; then
49+
echo "Exporting public keys"
50+
gpg --armor --export --output .build/pubkeys.gpg
51+
fi
52+
53+
cat <<EOF >${BUILD}/index.html
54+
<html>
55+
<head>
56+
<meta name="ac-discovery" content="${PREFIX} http://${PREFIX}/{os}/{arch}/{name}-{version}.{ext}">
57+
<meta name="ac-discovery-pubkeys" content="${PREFIX} pubkeys.gpg">
58+
</head>
59+
<body>
60+
</body>
61+
</html>
62+
EOF
63+
get_s3_bucket_location ${BUCKET}
64+
trust_url=${S3_URL_BASE}/pubkeys.gpg
65+
66+
# TODO: Non-public repos?
67+
is_website=1
68+
aws --region ${S3_BUCKET_REGION} s3api get-bucket-website --bucket ${BUCKET} >/dev/null 2>&1 || is_website=0
69+
if [[ ${is_website} == 0 ]]; then
70+
echo "Making bucket website-accesible"
71+
aws --region ${S3_BUCKET_REGION} s3api put-bucket-website --cli-input-json '{ "WebsiteConfiguration": { "IndexDocument": { "Suffix": "index.html" } } }' --bucket ${BUCKET}
72+
fi
73+
74+
aws --region ${S3_BUCKET_REGION} s3 cp --acl public-read ${BUILD}/pubkeys.gpg s3://${BUCKET}/
75+
aws --region ${S3_BUCKET_REGION} s3 cp --acl public-read ${BUILD}/index.html s3://${BUCKET}/
76+
else
77+
echo "Unknown repo schema: ${REPO}"
78+
echo "Please specify the repo like s3://<bucketname>"
79+
exit 1
80+
fi
81+
82+
echo "Trust the repo using:"
83+
echo "rkt trust --prefix ${PREFIX} ${trust_url}"
84+
}
85+
86+
function command-push() {
87+
IMAGE=$1
88+
REPO=$2
89+
90+
if [[ -z "${IMAGE}" || -z "${REPO}" ]]; then
91+
echo "syntax: $ME push <image> <repo>"
92+
echo "For example, $ME push imagedir/myimage.aci s3://aci.mydomain.com"
93+
exit 1
94+
fi
95+
96+
if [[ ! -f "${IMAGE}" ]]; then
97+
echo "Image not found: ${IMAGE}"
98+
exit 1
99+
fi
100+
101+
SIG=${IMAGE}.asc
102+
103+
MANIFEST=`actool cat-manifest ${IMAGE}`
104+
105+
IMAGE_NAME=`echo "${MANIFEST}" | python -c 'import json,sys;o=json.load(sys.stdin);print o["name"]'`
106+
if [[ -z "${IMAGE_NAME}" ]]; then
107+
echo "Image name could not be parsed from manifest"
108+
exit 1
109+
fi
110+
111+
IMAGE_VERSION=`echo "${MANIFEST}" | python -c 'import json,sys;o=json.load(sys.stdin);v=[l["value"] for l in o["labels"] if l["name"] == "version"];print "".join(v)'` || IMAGE_VERSION=""
112+
if [[ -z "${IMAGE_VERSION}" ]]; then
113+
echo "Image version could not be parsed from manifest"
114+
exit 1
115+
fi
116+
117+
echo "Using image name: ${IMAGE_NAME}, version: ${IMAGE_VERSION}"
118+
119+
if [[ ! -f "${SIG}" ]]; then
120+
echo "Signature file not found; signing"
121+
gpg --armor --output ${SIG} --detach-sign ${IMAGE}
122+
fi
123+
124+
if [[ "${REPO}" == s3://* ]]; then
125+
BUCKET=${REPO:5}
126+
127+
get_s3_bucket_location ${BUCKET}
128+
129+
target=linux/amd64/${IMAGE_NAME}-${IMAGE_VERSION}.aci
130+
run_url=${S3_URL_BASE}/${target}
131+
132+
echo "Uploading image to s3://${BUCKET}/${target}"
133+
aws --region ${S3_BUCKET_REGION} s3 cp --acl public-read ${IMAGE} s3://${BUCKET}/${target}
134+
135+
echo "Uploading signature to s3://${BUCKET}/${target}.asc"
136+
aws --region ${S3_BUCKET_REGION} s3 cp --acl public-read ${SIG} s3://${BUCKET}/${target}.asc
137+
else
138+
echo "Unknown repo schema: ${REPO}"
139+
echo "Please specify the repo like s3://<bucketname>"
140+
exit 1
141+
fi
142+
143+
echo "Image uploaded"
144+
echo "Run the image with: rkt run ${run_url}"
145+
echo "or, if you have set up a CNAME for the bucket:"
146+
echo "rkt run ${IMAGE_NAME}@${IMAGE_VERSION}"
147+
}
148+
149+
if [[ -z "${COMMAND}" ]]; then
150+
echo "syntax: $ME <command> <args...>"
151+
show-help
152+
exit 1
153+
fi
154+
155+
shift
156+
157+
case $COMMAND in
158+
init)
159+
command-init $@
160+
;;
161+
push)
162+
command-push $@
163+
;;
164+
help)
165+
show-help
166+
;;
167+
*)
168+
echo "Unknown command: ${COMMAND}"
169+
show-help
170+
exit 1
171+
;;
172+
esac
173+
exit 0
174+
175+
if [[ -z "${PREFIX}" || -z "${REPO}" ]]; then
176+
echo "syntax: $0 <prefix> <repo>"
177+
echo "For example, $0 aci.mydomain.com s3://aci.mydomain.com"
178+
exit 1
179+
fi
180+
181+
if [[ "${REPO}" == s3://* ]]; then
182+
BUCKET=${REPO:5}
183+
184+
# TODO: Create bucket automatically?
185+
186+
echo "Locating bucket..."
187+
bucket_region=`aws --output text s3api get-bucket-location --bucket ${BUCKET}`
188+
url_base=https://s3-${bucket_region}.amazonaws.com/${BUCKET}
189+
190+
# us-east-1 does not fit the pattern
191+
if [[ "${bucket_region}" == "None" ]]; then
192+
bucket_region="us-east-1"
193+
url_base=https://s3.amazonaws.com/${BUCKET}
194+
fi
195+
196+
mkdir -p .build/
197+
198+
if [[ ! -f .build/pubkeys.gpg ]]; then
199+
echo "Exporting public keys"
200+
gpg --armor --export --output .build/pubkeys.gpg
201+
fi
202+
203+
cat <<EOF >.build/index.html
204+
<html>
205+
<head>
206+
<meta name="ac-discovery" content="${PREFIX} http://${PREFIX}/{os}/{arch}/{name}-{version}.{ext}">
207+
<meta name="ac-discovery-pubkeys" content="${PREFIX} pubkeys.gpg">
208+
</head>
209+
<body>
210+
</body>
211+
</html>
212+
EOF
213+
214+
trust_url=${url_base}/${target}
215+
216+
aws --region ${bucket_region} s3 cp --acl public-read .build/pubkeys.gpg s3://${BUCKET}/
217+
aws --region ${bucket_region} s3 cp --acl public-read .build/index.html s3://${BUCKET}/
218+
else
219+
echo "Unknown repo schema: ${REPO}"
220+
echo "Please specify the repo like s3://<bucketname>"
221+
exit 1
222+
fi
223+
224+
echo "Trust the repo using:"
225+
echo "rkt trust --prefix ${PREFIX} ${url_base}/pubkeys.gpg"
226+

java7/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.build/
22
image.aci
3-
3+
image.aci.asc

java7/manifest

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
"acVersion": "0.5.1",
33
"acKind": "ImageManifest",
44
"name": "java",
5+
"labels": [
6+
{
7+
"name": "version",
8+
"value": "1.0.0"
9+
},
10+
{
11+
"name": "arch",
12+
"value": "amd64"
13+
},
14+
{
15+
"name": "os",
16+
"value": "linux"
17+
}
18+
],
519
"app": {
620
"exec": [ "/java", "-version" ],
721
"user": "0",

0 commit comments

Comments
 (0)