-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-docker.sh
46 lines (33 loc) · 1.09 KB
/
build-docker.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
#!/usr/bin/env bash
# usage
# build the latest image
# ./scripts/build-docker.sh
# build the image with a specified tag
# ./scripts/build-docker.sh v0.1.0
echo "current branch is $(git branch --show-current)"
# update git repository
# git pull --no-rebase
# update the latest golang image
docker pull golang:latest
# set GOPROXY environment variable
# GOPROXY=https://goproxy.cn
SOFT_NAME=replacer
# docker image name
SOFT_IMAGE_NAME=nosrc/${SOFT_NAME}
# docker image tag
SOFT_IMAGE_TAG=latest
# reset SOFT_IMAGE_TAG to the value of the first parameter provided by the user
if [ -n "$1" ]; then
SOFT_IMAGE_TAG=$1
fi
# remove the existing old image
docker rmi -f $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG
# build Dockerfile
docker build --build-arg GOPROXY=$GOPROXY -t $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG .
# remove dangling images
docker image prune -f
docker images | grep ${SOFT_NAME}
# run a container to print the soft version
docker run --rm --name running-${SOFT_NAME}-version $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG ${SOFT_NAME} -v
# push the image to the DockerHub
# docker push $SOFT_IMAGE_NAME:$SOFT_IMAGE_TAG