forked from alpine-docker/git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·38 lines (29 loc) · 1.31 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
#!/usr/bin/env bash
# Prerequisite
# Make sure you set secret enviroment variables in Travis CI
# DOCKER_USERNAME
# DOCKER_PASSWORD
set -e
image="alpine/git"
docker build --no-cache -t ${image}:latest .
DOCKER_PUSH="docker buildx build --no-cache --push --platform linux/amd64,linux/arm/v7,linux/arm64/v8,linux/arm/v6,linux/ppc64le,linux/s390x"
# add another tag with git version, with this way, we can check this git image health
VERSION=($(docker run -i --rm ${image}:latest version|awk '{print $NF}'))
echo ${VERSION}
# install crane
curl -LO https://github.com/google/go-containerregistry/releases/download/v0.11.0/go-containerregistry_Linux_x86_64.tar.gz
tar zxvf go-containerregistry_Linux_x86_64.tar.gz
chmod +x crane
if [[ "$CIRCLE_BRANCH" == "master" && "$CIRCLE_PULL_REQUEST" == "" ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker buildx create --use
${DOCKER_PUSH} -t ${image}:v${VERSION} .
./crane copy ${image}:v${VERSION} ${image}:latest
./crane copy ${image}:v${VERSION} ${image}:${VERSION}
fi
if [[ "$CIRCLE_BRANCH" == "feature/non-root" && "$CIRCLE_PULL_REQUEST" == "" ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
${DOCKER_PUSH} -t ${image}:user .
./crane copy ${image}:user ${image}:v${VERSION}-user
./crane copy ${image}:user ${image}:${VERSION}-user
fi