github.com/minio/console@v1.3.0/Makefile (about)

     1  PWD := $(shell pwd)
     2  GOPATH := $(shell go env GOPATH)
     3  # Sets the build version based on the output of the following command, if we are building for a tag, that's the build else it uses the current git branch as the build
     4  BUILD_VERSION:=$(shell git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null || git rev-parse --abbrev-ref HEAD 2>/dev/null)
     5  BUILD_TIME:=$(shell date 2>/dev/null)
     6  TAG ?= "minio/console:$(BUILD_VERSION)-dev"
     7  MINIO_VERSION ?= "quay.io/minio/minio:latest"
     8  TARGET_BUCKET ?= "target"
     9  NODE_VERSION := $(shell cat .nvmrc)
    10  
    11  default: console
    12  
    13  .PHONY: console
    14  console:
    15  	@echo "Building Console binary to './console'"
    16  	@(GO111MODULE=on CGO_ENABLED=0 go build -trimpath --tags=kqueue --ldflags "-s -w" -o console ./cmd/console)
    17  
    18  getdeps:
    19  	@mkdir -p ${GOPATH}/bin
    20  	@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin
    21  
    22  verifiers: getdeps fmt lint
    23  
    24  fmt:
    25  	@echo "Running $@ check"
    26  	@(env bash $(PWD)/verify-gofmt.sh)
    27  
    28  crosscompile:
    29  	@(env bash $(PWD)/cross-compile.sh $(arg1))
    30  
    31  lint:
    32  	@echo "Running $@ check"
    33  	@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
    34  	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
    35  
    36  lint-fix: getdeps ## runs golangci-lint suite of linters with automatic fixes
    37  	@echo "Running $@ check"
    38  	@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml --fix
    39  
    40  install: console
    41  	@echo "Installing console binary to '$(GOPATH)/bin/console'"
    42  	@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/console $(GOPATH)/bin/console
    43  	@echo "Installation successful. To learn more, try \"console --help\"."
    44  
    45  swagger-gen: clean-swagger swagger-console apply-gofmt
    46  	@echo "Done Generating swagger server code from yaml"
    47  
    48  apply-gofmt:
    49  	@echo "Applying gofmt to all generated an existing files"
    50  	@GO111MODULE=on gofmt -w .
    51  
    52  clean-swagger:
    53  	@echo "cleaning"
    54  	@rm -rf models
    55  	@rm -rf api/operations
    56  
    57  swagger-console:
    58  	@echo "Generating swagger server code from yaml"
    59  	@swagger generate server -A console --main-package=management --server-package=api --exclude-main -P models.Principal -f ./swagger.yml -r NOTICE
    60  	@echo "Generating typescript api"
    61  	@npx swagger-typescript-api -p ./swagger.yml -o ./web-app/src/api -n consoleApi.ts
    62  	@git restore api/server.go
    63  
    64  
    65  assets:
    66  	@(if [ -f "${NVM_DIR}/nvm.sh" ]; then \. "${NVM_DIR}/nvm.sh" && nvm install && nvm use && npm install -g yarn ; fi &&\
    67  	  cd web-app; yarn install --prefer-offline; make build-static; yarn prettier --write . --loglevel warn; cd ..)
    68  
    69  test-integration:
    70  	@(docker stop pgsqlcontainer || true)
    71  	@(docker stop minio || true)
    72  	@(docker stop minio2 || true)
    73  	@(docker network rm mynet123 || true)
    74  	@echo "create docker network to communicate containers MinIO & PostgreSQL"
    75  	@(docker network create --subnet=173.18.0.0/29 mynet123)
    76  	@echo "docker run with MinIO Version below:"
    77  	@echo $(MINIO_VERSION)
    78  	@echo "MinIO 1"
    79  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio --rm -p 9000:9000 -p 9091:9091 -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= $(MINIO_VERSION) server /data{1...4} --console-address ':9091' && sleep 5)
    80  	@echo "MinIO 2"
    81  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 --net=mynet123 -d --name minio2 --rm -p 9001:9001 -p 9092:9092 -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= $(MINIO_VERSION) server /data{1...4} --address ':9001' --console-address ':9092' && sleep 5)
    82  	@echo "Postgres"
    83  	@(docker run --net=mynet123 --ip=173.18.0.4 --name pgsqlcontainer --rm -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres && sleep 5)
    84  	@echo "execute test and get coverage for test-integration:"
    85  	@(cd integration && go test -coverpkg=../api -c -tags testrunmain . && mkdir -p coverage &&  ./integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/system.out)
    86  	@(docker stop pgsqlcontainer)
    87  	@(docker stop minio)
    88  	@(docker stop minio2)
    89  	@(docker network rm mynet123)
    90  
    91  test-replication:
    92  	@(docker stop minio || true)
    93  	@(docker stop minio1 || true)
    94  	@(docker stop minio2 || true)
    95  	@(docker network rm mynet123 || true)
    96  	@(docker network create mynet123)
    97  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 \
    98  	  --net=mynet123 -d \
    99  	  --name minio \
   100  	  --rm \
   101  	  -p 9000:9000 \
   102  	  -p 6000:6000 \
   103  	  -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= \
   104  	  -e MINIO_ROOT_USER="minioadmin" \
   105  	  -e MINIO_ROOT_PASSWORD="minioadmin" \
   106  	  $(MINIO_VERSION) server /data{1...4} \
   107  	  --address :9000 \
   108  	  --console-address :6000)
   109  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 \
   110  	  --net=mynet123 -d \
   111  	  --name minio1 \
   112  	  --rm \
   113  	  -p 9001:9001 \
   114  	  -p 6001:6001 \
   115  	  -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= \
   116  	  -e MINIO_ROOT_USER="minioadmin" \
   117  	  -e MINIO_ROOT_PASSWORD="minioadmin" \
   118  	  $(MINIO_VERSION) server /data{1...4} \
   119  	  --address :9001 \
   120  	  --console-address :6001)
   121  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 \
   122  	  --net=mynet123 -d \
   123  	  --name minio2 \
   124  	  --rm \
   125  	  -p 9002:9002 \
   126  	  -p 6002:6002 \
   127  	  -e MINIO_KMS_SECRET_KEY=my-minio-key:OSMM+vkKUTCvQs9YL/CVMIMt43HFhkUpqJxTmGl6rYw= \
   128  	  -e MINIO_ROOT_USER="minioadmin" \
   129  	  -e MINIO_ROOT_PASSWORD="minioadmin" \
   130  	  $(MINIO_VERSION) server /data{1...4} \
   131  	  --address :9002 \
   132  	  --console-address :6002)
   133  	@(cd replication && go test -coverpkg=../api -c -tags testrunmain . && mkdir -p coverage && ./replication.test -test.v -test.run "^Test*" -test.coverprofile=coverage/replication.out)
   134  	@(docker stop minio || true)
   135  	@(docker stop minio1 || true)
   136  	@(docker stop minio2 || true)
   137  	@(docker network rm mynet123 || true)
   138  
   139  test-sso-integration:
   140  	@echo "create the network in bridge mode to communicate all containers"
   141  	@(docker network create my-net)
   142  	@echo "run openldap container using MinIO Image: quay.io/minio/openldap:latest"
   143  	@(docker run \
   144  		-e LDAP_ORGANIZATION="MinIO Inc" \
   145  		-e LDAP_DOMAIN="min.io" \
   146  		-e LDAP_ADMIN_PASSWORD="admin" \
   147  		--network my-net \
   148  		-p 389:389 \
   149  		-p 636:636 \
   150  		--name openldap \
   151  		--detach quay.io/minio/openldap:latest)
   152  	@echo "Run Dex container using MinIO Image: quay.io/minio/dex:latest"
   153  	@(docker run \
   154  		-e DEX_ISSUER=http://dex:5556/dex \
   155  		-e DEX_CLIENT_REDIRECT_URI=http://127.0.0.1:9090/oauth_callback \
   156  		-e DEX_LDAP_SERVER=openldap:389 \
   157  		--network my-net \
   158  		-p 5556:5556 \
   159  		--name dex \
   160  		--detach quay.io/minio/dex:latest)
   161  	@echo "running minio server"
   162  	@(docker run \
   163  	-v /data1 -v /data2 -v /data3 -v /data4 \
   164  	--network my-net \
   165  	-d \
   166  	--name minio \
   167  	--rm \
   168  	-p 9000:9000 \
   169  	-p 9001:9001 \
   170  	-e MINIO_IDENTITY_OPENID_CLIENT_ID="minio-client-app" \
   171  	-e MINIO_IDENTITY_OPENID_CLIENT_SECRET="minio-client-app-secret" \
   172  	-e MINIO_IDENTITY_OPENID_CLAIM_NAME=name \
   173  	-e MINIO_IDENTITY_OPENID_CONFIG_URL=http://dex:5556/dex/.well-known/openid-configuration \
   174  	-e MINIO_IDENTITY_OPENID_REDIRECT_URI=http://127.0.0.1:9090/oauth_callback \
   175  	-e MINIO_ROOT_USER=minio \
   176  	-e MINIO_ROOT_PASSWORD=minio123 $(MINIO_VERSION) server /data{1...4} --address :9000 --console-address :9001)
   177  	@echo "run mc commands to set the policy"
   178  	@(docker run --name minio-client --network my-net -dit --entrypoint=/bin/sh minio/mc)
   179  	@(docker exec minio-client mc alias set myminio/ http://minio:9000 minio minio123)
   180  	@echo "adding policy to Dillon Harper to be able to login:"
   181  	@(cd sso-integration && docker cp allaccess.json minio-client:/ && docker exec minio-client mc admin policy create myminio "Dillon Harper" allaccess.json)
   182  	@echo "starting bash script"
   183  	@(env bash $(PWD)/sso-integration/set-sso.sh)
   184  	@echo "add python module"
   185  	@(pip3 install bs4)
   186  	@echo "Executing the test:"
   187  	@(cd sso-integration && go test -coverpkg=../api -c -tags testrunmain . && mkdir -p coverage && ./sso-integration.test -test.v -test.run "^Test*" -test.coverprofile=coverage/sso-system.out)
   188  
   189  test-permissions-1:
   190  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   191  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-1/")
   192  	@(docker stop minio)
   193  
   194  test-permissions-2:
   195  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   196  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-2/")
   197  	@(docker stop minio)
   198  
   199  test-permissions-3:
   200  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   201  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-3/")
   202  	@(docker stop minio)
   203  
   204  test-permissions-4:
   205  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   206  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-4/")
   207  	@(docker stop minio)
   208  
   209  test-permissions-5:
   210  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   211  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-5/")
   212  	@(docker stop minio)
   213  
   214  test-permissions-6:
   215  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   216  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-6/")
   217  	@(docker stop minio)
   218  
   219  test-permissions-7:
   220  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   221  	@(env bash $(PWD)/web-app/tests/scripts/permissions.sh "web-app/tests/permissions-7/")
   222  	@(docker stop minio)
   223  
   224  test-apply-permissions:
   225  	@(env bash $(PWD)/web-app/tests/scripts/initialize-env.sh)
   226  
   227  test-start-docker-minio:
   228  	@(docker run -v /data1 -v /data2 -v /data3 -v /data4 -d --name minio --rm -p 9000:9000 quay.io/minio/minio:latest server /data{1...4})
   229  
   230  initialize-permissions: test-start-docker-minio test-apply-permissions
   231  	@echo "Done initializing permissions test"
   232  
   233  cleanup-permissions:
   234  	@(env bash $(PWD)/web-app/tests/scripts/cleanup-env.sh)
   235  	@(docker stop minio)
   236  
   237  initialize-docker-network:
   238  	@(docker network create test-network)
   239  
   240  test-start-docker-minio-w-redirect-url: initialize-docker-network
   241  	@(docker run \
   242      -e MINIO_BROWSER_REDIRECT_URL='http://localhost:8000/console/subpath/' \
   243      -e MINIO_SERVER_URL='http://localhost:9000' \
   244      -v /data1 -v /data2 -v /data3 -v /data4 \
   245      -d --network host --name minio --rm\
   246      quay.io/minio/minio:latest server /data{1...4}) 
   247  
   248  test-start-docker-nginx-w-subpath:
   249  	@(docker run \
   250  	--network host \
   251  	-d --rm \
   252  	--add-host=host.docker.internal:host-gateway \
   253  	-v ./web-app/tests/subpath-nginx/nginx.conf:/etc/nginx/nginx.conf \
   254  	--name test-nginx nginx)
   255  
   256  test-initialize-minio-nginx: test-start-docker-minio-w-redirect-url test-start-docker-nginx-w-subpath
   257  
   258  cleanup-minio-nginx:
   259  	@(docker stop minio test-nginx & docker network rm test-network)
   260  
   261  # https://stackoverflow.com/questions/19200235/golang-tests-in-sub-directory
   262  # Note: go test ./... will run tests on the current folder and all subfolders.
   263  # This is needed because tests can be in the folder or sub-folder(s), let's include them all please!.
   264  test:
   265  	@echo "execute test and get coverage"
   266  	@(cd api && mkdir -p coverage && GO111MODULE=on go test ./... -test.v -coverprofile=coverage/coverage.out)
   267  
   268  
   269  # https://stackoverflow.com/questions/19200235/golang-tests-in-sub-directory
   270  # Note: go test ./... will run tests on the current folder and all subfolders.
   271  # This is since tests in pkg folder are in subfolders and were not executed.
   272  test-pkg:
   273  	@echo "execute test and get coverage"
   274  	@(cd pkg && mkdir -p coverage && GO111MODULE=on go test ./... -test.v -coverprofile=coverage/coverage-pkg.out)
   275  
   276  coverage:
   277  	@(GO111MODULE=on go test -v -coverprofile=coverage.out github.com/minio/console/api/... && go tool cover -html=coverage.out && open coverage.html)
   278  
   279  clean:
   280  	@echo "Cleaning up all the generated files"
   281  	@find . -name '*.test' | xargs rm -fv
   282  	@find . -name '*~' | xargs rm -fv
   283  	@rm -vf console
   284  
   285  docker:
   286  	@docker buildx build --output=type=docker --platform linux/amd64 -t $(TAG) --build-arg build_version=$(BUILD_VERSION) --build-arg build_time='$(BUILD_TIME)' --build-arg NODE_VERSION='$(NODE_VERSION)' .
   287  
   288  release: swagger-gen
   289  	@echo "Generating Release: $(RELEASE)"
   290  	@make assets
   291  	@git add -u .
   292  	@git add web-app/build/