forked from LabKey/Dockerfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
160 lines (128 loc) · 4.03 KB
/
Makefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
SHELL := /usr/bin/env bash
include .env
ifeq ($(strip $(findstring Darwin,$(shell uname -a 2>&1 ; ))),)
_G :=
else
_G := g
endif
DEBUG ?=
FROM_TAG ?= 17-jre-jammy
CACHE_FLAG ?= --no-cache
TAG_LATEST ?=
PUSH_LATEST ?=
IDENT ?= labkey
PULL_TAG ?= latest
AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity | jq -r '.Account' | grep -E '[0-9]{12}' || exit 1)
AWS_REGION ?= $(shell aws configure get region || exit 1)
LABKEY_VERSION ?= 21.5-SNAPSHOT
LABKEY_DISTRIBUTION ?= community
LABKEY_EK ?= 123abc456
# repo/image:tags must be lowercase
BUILD_VERSION ?= $(shell echo '$(LABKEY_VERSION)' | tr A-Z a-z)
BUILD_DISTRIBUTION := $(shell echo '$(LABKEY_DISTRIBUTION)' | tr A-Z a-z)
BUILD_REPO_URI ?= $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
BUILD_REPO_NAME := labkey/$(BUILD_DISTRIBUTION)
BUILD_REMOTE_REPO := $(BUILD_REPO_URI)/$(BUILD_REPO_NAME)
BUILD_LOCAL_TAG ?= $(BUILD_REPO_NAME):$(BUILD_VERSION)
BUILD_REMOTE_TAG ?= $(BUILD_REMOTE_REPO):$(BUILD_VERSION)
ifeq (1,$(DEBUG))
BUILD_LOCAL_TAG := $(addsuffix -debug,$(BUILD_LOCAL_TAG))
BUILD_REMOTE_TAG ?= $(addsuffix -debug,$(BUILD_REMOTE_TAG))
endif
define tc
$(shell printf "%steamcity[progressMessage '%s%n']" '##' '$1' ; )
endef
.PHONY: all build tag login push up up-build down clean
.EXPORT_ALL_VARIABLES:
# default actions are: login, build, tag, then push
all: login build tag push
build:
$(call tc,building docker container)
docker build \
--rm \
--compress \
--platform linux/amd64 \
$(CACHE_FLAG) \
-t $(BUILD_REPO_NAME):latest \
-t $(BUILD_LOCAL_TAG) \
--build-arg 'FROM_TAG=$(FROM_TAG)' \
--build-arg 'DEBUG=$(DEBUG)' \
--build-arg 'LABKEY_VERSION=$(LABKEY_VERSION)' \
--build-arg 'LABKEY_DISTRIBUTION=$(BUILD_DISTRIBUTION)' \
--build-arg 'LABKEY_EK=$(LABKEY_EK)' \
.
login:
$(call tc,logging in to ECR)
aws ecr get-login-password \
| docker login \
--username AWS \
--password-stdin \
$(BUILD_REPO_URI)
tag:
$(call tc,tagging docker container)
docker tag \
$(BUILD_LOCAL_TAG) \
$(BUILD_REMOTE_TAG);
if [ -n "$(TAG_LATEST)" ]; then \
docker tag \
$(BUILD_REPO_NAME):latest \
$(BUILD_REMOTE_REPO):latest; \
fi
push:
$(call tc,pushing $(BUILD_REMOTE_TAG) docker container)
docker push $(BUILD_REMOTE_TAG);
if [ -n "$(PUSH_LATEST)" ]; then \
docker push $(BUILD_REMOTE_REPO):latest; \
fi
up:
$(call tc,bringing up compose)
docker-compose up ${BUILD_DISTRIBUTION} -d
#|| docker-compose stop ${BUILD_DISTRIBUTION} pg-${BUILD_DISTRIBUTION}
up-allpg:
$(call tc,bringing up compose)
docker-compose up --abort-on-container-exit allpg \
|| docker-compose stop allpg pg-allpg
up-enterprise:
$(call tc,bringing up compose)
docker-compose up --abort-on-container-exit enterprise \
|| docker-compose stop enterprise pg-enterprise
up-lims_starter:
$(call tc,bringing up compose)
docker-compose up --abort-on-container-exit lims_starter \
|| docker-compose stop lims_starter pg-lims_starter
down:
$(call tc,tearing down compose)
docker-compose down -v --remove-orphans
clean:
docker images | grep -E '$(BUILD_REPO_NAME)|<none>' \
| awk '{print $$3}' | sort -u | $(_G)xargs -r docker image rm -f \
&& $(_G)find mounts/logs/ -name '*.log' -type f -print0 \
| $(_G)xargs -r -0 -t truncate -s0;
test: down
$(call tc,running smoke tests)
IDENT=${BUILD_DISTRIBUTION} docker-compose up --detach ${BUILD_DISTRIBUTION};
@./smoke.bash \
&& printf "##teamcity[progressMessage '%s']\n" 'smoke test succeeded' \
|| printf "##teamcity[buildProblem description='%s' identity='%s']\n" \
'smoke test failed' \
'failure'
IDENT=${BUILD_DISTRIBUTION} docker-compose down -v
pull: login
docker pull $(BUILD_REMOTE_REPO):$(PULL_TAG)
untagged: login
$(call tc,removing untagged images from remote repo)
aws ecr \
list-images \
--query 'imageIds[?imageTag == ""].imageDigest' \
--repository-name $(BUILD_REPO_NAME) \
--output text \
| $(_G)xargs \
-d $$'\t' \
-t \
-I{} \
-r \
aws ecr \
batch-delete-image \
--repository-name $(BUILD_REPO_NAME) \
--image-ids 'imageDigest={}' \
| cat