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