Skip to content

Commit 6014b61

Browse files
committed
build: customize image time zone
1 parent 8067da3 commit 6014b61

File tree

12 files changed

+54
-30
lines changed

12 files changed

+54
-30
lines changed

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,30 @@ image-build-local: build
134134
.PHONY: image-build
135135
# Build image for remote repositories, use binary files to build, e.g. make image-build REPO_HOST=addr TAG=latest
136136
image-build:
137+
@if [ -z "$(REPO_HOST)" ]; then \
138+
echo "ERROR: REPO_HOST is required. Usage: make image-build REPO_HOST=xxx"; \
139+
exit 1; \
140+
fi
137141
@bash scripts/image-build.sh $(REPO_HOST) $(TAG)
138142

139143

140144
.PHONY: image-build2
141145
# Build image for remote repositories, phase II build, e.g. make image-build2 REPO_HOST=addr TAG=latest
142146
image-build2:
147+
@if [ -z "$(REPO_HOST)" ]; then \
148+
echo "ERROR: REPO_HOST is required. Usage: make image-build2 REPO_HOST=xxx"; \
149+
exit 1; \
150+
fi
143151
@bash scripts/image-build2.sh $(REPO_HOST) $(TAG)
144152

145153

146154
.PHONY: image-push
147155
# Push docker image to remote repositories, e.g. make image-push REPO_HOST=addr TAG=latest
148156
image-push:
157+
@if [ -z "$(REPO_HOST)" ]; then \
158+
echo "ERROR: REPO_HOST is required. Usage: make image-push REPO_HOST=xxx TAG=latest"; \
159+
exit 1; \
160+
fi
149161
@bash scripts/image-push.sh $(REPO_HOST) $(TAG)
150162

151163

Makefile-for-http

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,30 @@ image-build-local: build
8787
.PHONY: image-build
8888
# Build image for remote repositories, use binary files to build, e.g. make image-build REPO_HOST=addr TAG=latest
8989
image-build:
90+
@if [ -z "$(REPO_HOST)" ]; then \
91+
echo "ERROR: REPO_HOST is required. Usage: make image-build REPO_HOST=xxx"; \
92+
exit 1; \
93+
fi
9094
@bash scripts/image-build.sh $(REPO_HOST) $(TAG)
9195

9296

9397
.PHONY: image-build2
9498
# Build image for remote repositories, phase II build, e.g. make image-build2 REPO_HOST=addr TAG=latest
9599
image-build2:
100+
@if [ -z "$(REPO_HOST)" ]; then \
101+
echo "ERROR: REPO_HOST is required. Usage: make image-build2 REPO_HOST=xxx"; \
102+
exit 1; \
103+
fi
96104
@bash scripts/image-build2.sh $(REPO_HOST) $(TAG)
97105

98106

99107
.PHONY: image-push
100108
# Push docker image to remote repositories, e.g. make image-push REPO_HOST=addr TAG=latest
101109
image-push:
110+
@if [ -z "$(REPO_HOST)" ]; then \
111+
echo "ERROR: REPO_HOST is required. Usage: make image-push REPO_HOST=xxx TAG=latest"; \
112+
exit 1; \
113+
fi
102114
@bash scripts/image-push.sh $(REPO_HOST) $(TAG)
103115

104116

cmd/perftest/Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
FROM alpine:latest
22
LABEL maintainer="zhufuyi <[email protected]>"
33

4-
# set the time zone to Shanghai
5-
#RUN apk add tzdata \
6-
# && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
7-
# && echo "Asia/Shanghai" > /etc/timezone \
8-
# && apk del tzdata
9-
104
COPY perftest /app/perftest
115
RUN chmod +x /app/perftest
126

cmd/perftest/build-perftest-image.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ checkResult $?
3939
rmFile perftest
4040

4141
# delete none image
42-
noneImages=$(docker images --filter "dangling=true" -q)
42+
noneImages=$(docker images --filter "dangling=true" -q | grep "${zhufuyi/perftest}")
4343
if [ -n "$noneImages" ]; then
44-
docker rmi $noneImages > /dev/null
44+
docker rmi $noneImages > /dev/null 2>&1 || true
4545
fi
4646

4747
# push image to docker hub

deployments/docker-compose/docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ services:
88
command: ["./serverNameExample", "-c", "/app/configs/serverNameExample.yml"]
99
volumes:
1010
- $PWD/configs:/app/configs
11+
- /etc/localtime:/etc/localtime:ro # mount the local time file
12+
#environment:
13+
# - TZ=Asia/Shanghai
1114
# todo generate docker-compose.yml code for http or grpc here
1215
# delete the templates code start
1316
ports:

deployments/kubernetes/serverNameExample-deployment.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ spec:
3131
- name: server-name-example-vl
3232
mountPath: /app/configs/
3333
readOnly: true
34-
# todo generate k8s-deployment.yml code for http or grpc here
34+
- name: host-timezone
35+
mountPath: /etc/localtime
36+
readOnly: true
37+
#env:
38+
# - name: TZ
39+
# value: "Asia/Shanghai"
40+
# todo generate k8s-deployment.yml code for http or grpc here
3541
# delete the templates code start
3642
ports:
3743
- name: http-port
@@ -73,3 +79,7 @@ spec:
7379
- name: server-name-example-vl
7480
configMap:
7581
name: server-name-example-config
82+
- name: host-timezone
83+
hostPath:
84+
path: /etc/localtime
85+
type: File

scripts/build/Dockerfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
FROM alpine:latest
22
MAINTAINER zhufuyi "[email protected]"
33

4-
# set the time zone to Shanghai
5-
RUN apk add tzdata \
6-
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
7-
&& echo "Asia/Shanghai" > /etc/timezone \
8-
&& apk del tzdata
9-
104
# todo generate dockerfile code for http or grpc here
115
# delete the templates code start
126

scripts/build/Dockerfile_build

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ RUN cd $GOPATH/pkg/mod/github.com/grpc-ecosystem/[email protected] \
2828
FROM alpine:latest
2929
MAINTAINER zhufuyi "[email protected]"
3030

31-
# set the time zone to Shanghai
32-
RUN apk add tzdata \
33-
&& cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
34-
&& echo "Asia/Shanghai" > /etc/timezone \
35-
&& apk del tzdata
36-
3731
# add curl, used in the http service check, if deployed in k8s, can be installed without
3832
RUN apk add curl
3933
# add grpc_health_probe for health check of grpc service

scripts/deploy-binary.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@
22

33
set serviceName "serverNameExample"
44

5+
if {$argc < 3} {
6+
puts "Usage: $argv0 username password ipAddr"
7+
exit 1
8+
}
9+
510
# parameters
611
set username [lindex $argv 0]
712
set password [lindex $argv 1]
8-
set hostname [lindex $argv 2]
13+
set ipAddr [lindex $argv 2]
914

1015
set timeout 30
1116

12-
spawn scp -r ./${serviceName}-binary.tar.gz ${username}@${hostname}:/tmp/
17+
spawn scp -r ./${serviceName}-binary.tar.gz ${username}@${ipAddr}:/tmp/
1318
#expect "*yes/no*"
1419
#send "yes\r"
1520
expect "*password:*"
1621
send "${password}\r"
1722
expect eof
1823

19-
spawn ssh ${username}@${hostname}
24+
spawn ssh ${username}@${ipAddr}
2025
#expect "*yes/no*"
2126
#send "yes\r"
2227
expect "*password:*"

scripts/image-build-local.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ if [ -d "${DOCKERFILE_PATH}/configs" ]; then
4848
fi
4949

5050
# delete none image
51-
noneImages=$(docker images | grep "<none>" | awk '{print $3}')
51+
noneImages=$(docker images | grep "${IMAGE_NAME}" | grep "<none>" | awk '{print $3}')
5252
if [ "X${noneImages}" != "X" ]; then
53-
docker rmi ${noneImages} > /dev/null
53+
docker rmi ${noneImages} > /dev/null 2>&1 || true
5454
fi
5555
exit 0

0 commit comments

Comments
 (0)