forked from nwesterhausen/domain-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·49 lines (39 loc) · 1.28 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# Automatically docker build and tag for current version
# Then upload to GH Packages
#
# Requires jq and ~/.gh_token
# Github Username
USERNAME=nwesterhausen
# Get repo part of repository
IMAGE_PREFIX=$(jq .repository.url package.json | cut -d/ -f 5 | cut -d. -f 1)
# Name for this image
IMAGE=server
# Get version tag from package.json
TAG=$(jq .version package.json | cut -d\" -f 2)
# Concat strings
GH_TAGBASE="docker.pkg.github.com/$USERNAME/$IMAGE_PREFIX/$IMAGE"
DOCKER_TAGBASE="$USERNAME/$IMAGE_PREFIX"
# Build the docker image
docker build -t "$DOCKER_TAGBASE" .
# Grab the image ID
IMAGE_ID=$(docker images -q "$DOCKER_TAGBASE")
echo $IMAGE_ID
# Tag the image
docker tag $IMAGE_ID "$GH_TAGBASE:$TAG"
docker tag $IMAGE_ID "$GH_TAGBASE:latest"
docker tag $IMAGE_ID "$DOCKER_TAGBASE:$TAG"
docker tag $IMAGE_ID "$DOCKER_TAGBASE:latest"
# Login to gh packages docker repo
cat ~/.gh_token | docker login docker.pkg.github.com -u nwesterhausen --password-stdin
# Push the images
docker push "$GH_TAGBASE:$TAG"
docker push "$GH_TAGBASE:latest"
# Login to docker.io
docker login
# Push the images
docker push "$DOCKER_TAGBASE:$TAG"
docker push "$DOCKER_TAGBASE:latest"
# You could then go on to include other docker package repositories here,
# by tagging and pushing as appropriate.