18874: Merge commit '6f8dcb2b13f3058db656908fb26b09e23b527f08' into 18874-merge-wb2
[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 ARVADOS_DIRECTORY?=unset
27
28 DESCRIPTION=Arvados Workbench2 - Arvados is a free and open source platform for big data science.
29 MAINTAINER=Arvados Package Maintainers <packaging@arvados.org>
30
31 # DEST_DIR will have the build package copied.
32 DEST_DIR=/var/www/$(APP_NAME)/workbench2/
33
34 # Debian package file
35 DEB_FILE=$(APP_NAME)_$(VERSION)-$(ITERATION)_amd64.deb
36
37 # redHat package file
38 RPM_FILE=$(APP_NAME)-$(VERSION)-$(ITERATION).x86_64.rpm
39
40 export WORKSPACE?=$(shell pwd)
41
42 .PHONY: help clean* yarn-install test build packages packages-with-version integration-tests-in-docker
43
44 help:
45         @echo >&2
46         @echo >&2 "There is no default make target here.  Did you mean 'make test'?"
47         @echo >&2
48         @echo >&2 "More info:"
49         @echo >&2 "  Installing              --> http://doc.arvados.org/install"
50         @echo >&2 "  Developing/contributing --> https://dev.arvados.org"
51         @echo >&2 "  Project home            --> https://arvados.org"
52         @echo >&2
53         @false
54
55 clean-deb:
56         rm -f $(WORKSPACE)/*.deb
57
58 clean-rpm:
59         rm -f $(WORKSPACE)/*.rpm
60
61 clean-node-modules:
62         rm -rf $(WORKSPACE)/node_modules
63
64 clean: clean-rpm clean-deb clean-node-modules
65
66 arvados-server-install: check-arvados-directory
67         cd $(ARVADOS_DIRECTORY)
68         go mod download
69         cd cmd/arvados-server
70         go install
71         cd -
72         ls -l $(GOPATH)/bin/arvados-server
73         $(GOPATH)/bin/arvados-server install -type test
74
75 yarn-install:
76         yarn install
77
78 unit-tests: yarn-install
79         yarn test --no-watchAll --bail --ci
80
81 integration-tests: yarn-install check-arvados-directory
82         yarn run cypress install
83         $(WORKSPACE)/tools/run-integration-tests.sh -a $(ARVADOS_DIRECTORY)
84
85 integration-tests-in-docker: workbench2-build-image check-arvados-directory
86         docker run -ti -v$(PWD):/usr/src/workbench2 -v$(ARVADOS_DIRECTORY):/usr/src/arvados -w /usr/src/workbench2 -e ARVADOS_DIRECTORY=/usr/src/arvados workbench2-build make arvados-server-install integration-tests
87
88 unit-tests-in-docker: workbench2-build-image check-arvados-directory
89         docker run -ti -v$(PWD):/usr/src/workbench2 -v$(ARVADOS_DIRECTORY):/usr/src/arvados -w /usr/src/workbench2 -e ARVADOS_DIRECTORY=/usr/src/arvados workbench2-build make arvados-server-install unit-tests
90
91 test: unit-tests integration-tests
92
93 build: yarn-install
94         VERSION=$(VERSION) BUILD_NUMBER=$(BUILD_NUMBER) GIT_COMMIT=$(GIT_COMMIT) yarn build
95
96 $(DEB_FILE): build
97         fpm \
98          -s dir \
99          -t deb \
100          -n "$(APP_NAME)" \
101          -v "$(VERSION)" \
102          --iteration "$(ITERATION)" \
103          --vendor="The Arvados Authors" \
104          --maintainer="$(MAINTAINER)" \
105          --url="https://arvados.org" \
106          --license="GNU Affero General Public License, version 3.0" \
107          --description="$(DESCRIPTION)" \
108          --config-files="etc/arvados/$(APP_NAME)/workbench2.example.json" \
109         $(WORKSPACE)/build/=$(DEST_DIR) \
110         etc/arvados/workbench2/workbench2.example.json=/etc/arvados/$(APP_NAME)/workbench2.example.json
111
112 $(RPM_FILE): build
113         fpm \
114          -s dir \
115          -t rpm \
116          -n "$(APP_NAME)" \
117          -v "$(VERSION)" \
118          --iteration "$(ITERATION)" \
119          --vendor="The Arvados Authors" \
120          --maintainer="$(MAINTAINER)" \
121          --url="https://arvados.org" \
122          --license="GNU Affero General Public License, version 3.0" \
123          --description="$(DESCRIPTION)" \
124          --config-files="etc/arvados/$(APP_NAME)/workbench2.example.json" \
125          $(WORKSPACE)/build/=$(DEST_DIR) \
126         etc/arvados/workbench2/workbench2.example.json=/etc/arvados/$(APP_NAME)/workbench2.example.json
127
128 copy: $(DEB_FILE) $(RPM_FILE)
129         for target in $(TARGETS); do \
130                 mkdir -p "packages/$$target" && \
131                 case "$$target" in \
132                         centos*|rocky*) cp -p "$(RPM_FILE)" "packages/$$target" ;; \
133                         debian*|ubuntu*) cp -p "$(DEB_FILE)" "packages/$$target" ;; \
134                         *) echo "Unknown copy target $$target"; exit 1 ;; \
135                 esac ; \
136         done ; \
137         rm -f "$(DEB_FILE)" "$(RPM_FILE)"
138
139 # use FPM to create DEB and RPM
140 packages: copy
141
142 check-arvados-directory:
143         @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
144         @if ! test -d "${ARVADOS_DIRECTORY}"; then echo "the environment variable ARVADOS_DIRECTORY does not point at a directory"; exit 1; fi
145
146 packages-in-docker: check-arvados-directory workbench2-build-image
147         docker run --env ci="true" \
148                 --env ARVADOS_DIRECTORY=/tmp/arvados \
149                 --env APP_NAME=${APP_NAME} \
150                 --env ITERATION=${ITERATION} \
151                 --env TARGETS="${TARGETS}" \
152                 -w="/tmp/workbench2" \
153                 -t -v ${WORKSPACE}:/tmp/workbench2 \
154                 -v ${ARVADOS_DIRECTORY}:/tmp/arvados workbench2-build:latest \
155                 make packages
156
157 workbench2-build-image:
158         (cd docker && docker build -t workbench2-build .)