forked from barracuda-cloudgen-access/pyinstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·69 lines (57 loc) · 1.83 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
#
# Copyright (c) 2018, Fyde, Inc.
# All rights reserved.
#
# Create image
# Only setup error handling if we're not running in an interactive shell
if [[ ! $- =~ .*i.* ]] ; then
set -e
fi
# Check for required vars
if [ -n "$CI" ]; then
DOCKER_REGISTRY_PASS="${DOCKER_REGISTRY_PASS:?"DOCKER_REGISTRY_PASS not set"}"
DOCKER_REGISTRY_URL="${DOCKER_REGISTRY_URL:?"DOCKER_REGISTRY_URL not set"}"
DOCKER_REGISTRY_USER="${DOCKER_REGISTRY_USER:?"DOCKER_REGISTRY_USER not set"}"
DOCKER_TAG="${DOCKER_TAG:?"DOCKER_TAG not set"}"
else
DOCKER_TAG=fydeinc/pyinstaller
fi
if [ -z "$CI_COMMIT_REF_SLUG" ]; then
CI_COMMIT_REF_SLUG="$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)"
fi
if [[ "$CI_COMMIT_REF_SLUG" = "main" ]]; then
DOCKER_TAG="$DOCKER_TAG:latest"
NO_CACHE="--no-cache"
else
NO_CACHE=""
DOCKER_TAG_LATEST="$DOCKER_TAG:latest"
DOCKER_TAG="$DOCKER_TAG:$CI_COMMIT_REF_SLUG"
fi
echo "$DOCKER_TAG"
echo "Building docker with tag $DOCKER_TAG"
if [ -n "$DOCKER_REGISTRY_USER" ]; then
echo "Docker Login"
echo "$DOCKER_REGISTRY_PASS" | docker login --username "$DOCKER_REGISTRY_USER" --password-stdin "$DOCKER_REGISTRY_URL"
fi
if [ -n "$DOCKER_REGISTRY_URL" ]; then
DOCKER_TAG="$DOCKER_REGISTRY_URL/$DOCKER_TAG"
fi
if [ -n "$DOCKER_REGISTRY_USER" ]; then
echo "Pull Image"
docker pull "$DOCKER_TAG" || true
fi
echo "Build Image"
docker build --rm $NO_CACHE -t "$DOCKER_TAG" .
echo "Image info"
docker images "$DOCKER_TAG"
if [ -n "$DOCKER_REGISTRY_USER" ]; then
echo "Send Image to Registry"
docker push "$DOCKER_TAG"
# Also push latest in dev
if [[ -n "$DOCKER_TAG_LATEST" ]]; then
DOCKER_TAG_LATEST="$DOCKER_REGISTRY_URL/$DOCKER_TAG_LATEST"
docker tag "$DOCKER_TAG" "$DOCKER_TAG_LATEST"
docker push "$DOCKER_TAG_LATEST"
fi
fi