-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·66 lines (56 loc) · 1.79 KB
/
deploy.sh
File metadata and controls
executable file
·66 lines (56 loc) · 1.79 KB
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
#!/bin/bash
# 1. Format of docker image is $DOCKER_REPOSITORY/$IMAGE:$DEPLOY_ENV-$APP_VERSION.$TIMESTAMP
# for example 3dsinteractive/automation-technology:prd-1.0.20210118001006
APP_VERSION=1.0
TIMESTAMP=20210118001006
DEPLOY_ENV=prd
DOCKER_REPOSITORY=$DOCKER_USER
# 2. commit will push docker image to repository
function commit() {
local IMAGE=$1
echo "docker push image : $DOCKER_REPOSITORY/$IMAGE:$DEPLOY_ENV-$APP_VERSION.$TIMESTAMP"
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker push $DOCKER_REPOSITORY/$IMAGE:$DEPLOY_ENV-$APP_VERSION.$TIMESTAMP
}
# 3. build_api is the main function to build Dockerfile
function build_api() {
local IMAGE=automation-technology
# If found go in default path, it will use go from default path
GO=/usr/local/go/bin/go
if [ -f "$GO" ]; then
/usr/local/go/bin/go mod init automationworkshop/main
/usr/local/go/bin/go mod tidy
/usr/local/go/bin/go get
/usr/local/go/bin/go mod vendor
else
go mod init automationworkshop/main
go mod tidy
go get
go mod vendor
fi
# Build the Dockerfile
docker build -f Dockerfile -t $DOCKER_REPOSITORY/$IMAGE:$DEPLOY_ENV-$APP_VERSION.$TIMESTAMP .
commit $IMAGE
}
# 4. Validate APP_VERSION must not empty
if [ "$APP_VERSION" = "" ]; then
echo -e "APP_VERSION cannot be blank"
exit 1
fi
# 5. Validate TIMESTAMP must not empty
if [ "$TIMESTAMP" = "" ]; then
echo -e "TIMESTAMP cannot be blank"
exit 1
fi
# 6. Validate DEPLOY_ENV must not empty
if [ "$DEPLOY_ENV" == "" ]; then
echo -e "DEPLOY_ENV cannot be blank"
exit 1
fi
# 7. Validate DOCKER_REPOSITORY must not empty
if [ "$DOCKER_REPOSITORY" == "" ]; then
echo -e "DOCKER_REPOSITORY cannot be blank"
exit 1
fi
# 8. Run main build process
build_api