Merge branch '15317-metrics'
[arvados.git] / services / workbench2 / Makefile
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 # Use bash, and run all lines in each recipe as one shell command
6 SHELL := /bin/bash
7 .ONESHELL:
8
9 GOPATH?=~/go
10 APP_NAME?=arvados-workbench2
11
12 # Cypress test file that can be passed to the integration-test target
13 SPECFILE?=ALL
14
15 # VERSION uses all the above to produce X.Y.Z.timestamp
16 # something in the lines of 1.2.0.20180612145021, this will be the package version
17 # it can be overwritten when invoking make as in make packages VERSION=1.2.0
18 VERSION?=$(shell ./version-at-commit.sh HEAD)
19 # We don't use BUILD_NUMBER at the moment, but it needs to be defined
20 BUILD_NUMBER?=0
21 GIT_COMMIT?=$(shell git rev-parse --short HEAD)
22
23 # ITERATION is the package iteration, intended for manual change if anything non-code related
24 # changes in the package. (i.e. example config files externally added
25 ITERATION?=1
26
27 TARGETS?=rocky8 debian11 debian12 ubuntu2004 ubuntu2204
28
29 DESCRIPTION=Arvados Workbench2 - Arvados is a free and open source platform for big data science.
30 MAINTAINER=Arvados Package Maintainers <packaging@arvados.org>
31
32 # DEST_DIR will have the build package copied.
33 DEST_DIR=/var/www/$(APP_NAME)/workbench2/
34
35 # Debian package file
36 DEB_FILE=$(APP_NAME)_$(VERSION)-$(ITERATION)_amd64.deb
37
38 # redHat package file
39 RPM_FILE=$(APP_NAME)-$(VERSION)-$(ITERATION).x86_64.rpm
40
41 GOPATH=$(shell go env GOPATH)
42 export WORKSPACE?=$(shell pwd)
43
44 ARVADOS_DIRECTORY?=$(shell env -C $(WORKSPACE) git rev-parse --show-toplevel)
45
46 .PHONY: help clean* yarn-install test build packages packages-with-version integration-tests-in-docker
47
48 help:
49         @echo >&2
50         @echo >&2 "There is no default make target here.  Did you mean 'make test'?"
51         @echo >&2
52         @echo >&2 "More info:"
53         @echo >&2 "  Installing              --> http://doc.arvados.org/install"
54         @echo >&2 "  Developing/contributing --> https://dev.arvados.org"
55         @echo >&2 "  Project home            --> https://arvados.org"
56         @echo >&2
57         @false
58
59 clean-deb:
60         rm -f $(WORKSPACE)/*.deb
61
62 clean-rpm:
63         rm -f $(WORKSPACE)/*.rpm
64
65 clean-node-modules:
66         rm -rf $(WORKSPACE)/node_modules
67
68 clean: clean-rpm clean-deb clean-node-modules
69
70 arvados-server-install: check-arvados-directory
71         cd $(ARVADOS_DIRECTORY)
72         go mod download
73         cd cmd/arvados-server
74         echo GOPATH is $(GOPATH)
75         GOFLAGS=-buildvcs=false go install
76         cd -
77         ls -l $(GOPATH)/bin/arvados-server
78         $(GOPATH)/bin/arvados-server install -type test
79
80 yarn-install:
81         yarn install
82
83 unit-tests: yarn-install
84         yarn test --no-watchAll --bail --ci
85
86 integration-tests: yarn-install check-arvados-directory
87         yarn run cypress install
88 ifeq ($(SPECFILE), ALL)
89         $(WORKSPACE)/tools/run-integration-tests.sh -a $(ARVADOS_DIRECTORY)
90 else
91         $(WORKSPACE)/tools/run-integration-tests.sh -a $(ARVADOS_DIRECTORY) -- --spec $(SPECFILE)
92 endif
93
94 integration-tests-in-docker: workbench2-build-image check-arvados-directory
95         docker run -ti --rm \
96                 --env ARVADOS_DIRECTORY=/usr/src/arvados \
97                 --env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
98                 -v $(WORKSPACE):/usr/src/arvados/services/workbench2 \
99                 -v $(ARVADOS_DIRECTORY):/usr/src/arvados \
100                 -w /usr/src/arvados/services/workbench2 \
101                 workbench2-build \
102                 make arvados-server-install integration-tests SPECFILE=$(SPECFILE)
103
104 unit-tests-in-docker: workbench2-build-image check-arvados-directory
105         docker run -ti --rm \
106                 --env ARVADOS_DIRECTORY=/usr/src/arvados \
107                 --env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
108                 -v $(WORKSPACE):/usr/src/arvados/services/workbench2 \
109                 -v $(ARVADOS_DIRECTORY):/usr/src/arvados \
110                 -w /usr/src/arvados/services/workbench2 \
111                 workbench2-build \
112                 make arvados-server-install unit-tests
113
114 tests-in-docker: workbench2-build-image check-arvados-directory
115         docker run -ti --rm \
116                 --env ARVADOS_DIRECTORY=/usr/src/arvados \
117                 --env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
118                 --env ci="${ci}" \
119                 -v $(WORKSPACE):/usr/src/arvados/services/workbench2 \
120                 -v$(ARVADOS_DIRECTORY):/usr/src/arvados \
121                 -w /usr/src/arvados/services/workbench2 \
122                 workbench2-build \
123                 make test
124
125 test: unit-tests integration-tests
126
127 build: yarn-install
128         VERSION=$(VERSION) BUILD_NUMBER=$(BUILD_NUMBER) GIT_COMMIT=$(GIT_COMMIT) yarn build
129
130 $(DEB_FILE): build
131         fpm \
132          -s dir \
133          -t deb \
134          -n "$(APP_NAME)" \
135          -v "$(VERSION)" \
136          --iteration "$(ITERATION)" \
137          --vendor="The Arvados Authors" \
138          --maintainer="$(MAINTAINER)" \
139          --url="https://arvados.org" \
140          --license="GNU Affero General Public License, version 3.0" \
141          --description="$(DESCRIPTION)" \
142          --config-files="etc/arvados/$(APP_NAME)/workbench2.example.json" \
143         $(WORKSPACE)/build/=$(DEST_DIR) \
144         etc/arvados/workbench2/workbench2.example.json=/etc/arvados/$(APP_NAME)/workbench2.example.json
145
146 $(RPM_FILE): build
147         fpm \
148          -s dir \
149          -t rpm \
150          -n "$(APP_NAME)" \
151          -v "$(VERSION)" \
152          --iteration "$(ITERATION)" \
153          --vendor="The Arvados Authors" \
154          --maintainer="$(MAINTAINER)" \
155          --url="https://arvados.org" \
156          --license="GNU Affero General Public License, version 3.0" \
157          --description="$(DESCRIPTION)" \
158          --config-files="etc/arvados/$(APP_NAME)/workbench2.example.json" \
159          $(WORKSPACE)/build/=$(DEST_DIR) \
160         etc/arvados/workbench2/workbench2.example.json=/etc/arvados/$(APP_NAME)/workbench2.example.json
161
162 copy: $(DEB_FILE) $(RPM_FILE)
163         for target in $(TARGETS); do \
164                 mkdir -p "packages/$$target" && \
165                 case "$$target" in \
166                         centos*|rocky*) cp -p "$(RPM_FILE)" "packages/$$target" ;; \
167                         debian*|ubuntu*) cp -p "$(DEB_FILE)" "packages/$$target" ;; \
168                         *) echo "Unknown copy target $$target"; exit 1 ;; \
169                 esac ; \
170         done ; \
171         rm -f "$(DEB_FILE)" "$(RPM_FILE)"
172
173 # use FPM to create DEB and RPM
174 packages: copy
175
176 check-arvados-directory:
177         @if test "${ARVADOS_DIRECTORY}" == "unset"; then echo "the environment variable ARVADOS_DIRECTORY must be set to the path of an arvados git checkout"; exit 1; fi
178         @if ! test -d "${ARVADOS_DIRECTORY}"; then echo "the environment variable ARVADOS_DIRECTORY does not point at a directory"; exit 1; fi
179
180 packages-in-docker: check-arvados-directory workbench2-build-image
181         docker run -t --rm --env ci="true" \
182                 --env ARVADOS_DIRECTORY=/tmp/arvados \
183                 --env APP_NAME=${APP_NAME} \
184                 --env VERSION="${VERSION}" \
185                 --env ITERATION=${ITERATION} \
186                 --env TARGETS="${TARGETS}" \
187                 --env MAINTAINER="${MAINTAINER}" \
188                 --env DESCRIPTION="${DESCRIPTION}" \
189                 --env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
190                 -w "/tmp/workbench2" \
191                 -v ${WORKSPACE}:/tmp/workbench2 \
192                 -v ${ARVADOS_DIRECTORY}:/tmp/arvados \
193                 workbench2-build:latest \
194                 sh -c 'git config --global --add safe.directory /tmp/workbench2 && make packages'
195
196 workbench2-build-image:
197         docker inspect workbench2-build &> /dev/null || \
198                 docker build -t workbench2-build -f docker/Dockerfile ${ARVADOS_DIRECTORY}