Skip to content

Commit

Permalink
ci: Build less and therefore faster (argoproj#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Apr 29, 2020
1 parent 56143eb commit c05c385
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 306 deletions.
20 changes: 10 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ commands:
echo " token: xxxxxx" >> ~/.kube/config
- run:
name: Start Argo
command: mkdir dist && KUBECONFIG=~/.kube/config make start DB=$DB E2E_EXECUTOR=docker DEV_IMAGE=true
- run:
name: Establish port forward
command: make pf
command: |
echo '127.0.0.1 minio' | sudo tee -a /etc/hosts
echo '127.0.0.1 postgres' | sudo tee -a /etc/hosts
echo '127.0.0.1 mysql' | sudo tee -a /etc/hosts
mkdir dist
KUBECONFIG=~/.kube/config make start DB=$DB E2E_EXECUTOR=docker DEV_IMAGE=true
# CircleCI will kill spawned processes, so lets block for 20m
sleep 20m
background: true
- run:
name: Sleep for short while
command: sleep 10s
- run:
name: Follow logs, to help diagnose failures
command: make logs
background: true
name: Wait for Argo Server to be ready
command: make wait
- run:
name: Run tests
command: |
Expand Down
143 changes: 60 additions & 83 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ STATIC_BUILD ?= true
CI ?= false
DB ?= postgres
K3D := $(shell if [ "`kubectl config current-context`" = "k3s-default" ]; then echo true; else echo false; fi)
ARGO_TOKEN = $(shell kubectl -n argo get secret -o name | grep argo-server | xargs kubectl -n argo get -o jsonpath='{.data.token}' | base64 --decode)
# which components to start, useful if you want to disable them to debug
COMPONENTS := controller,argo-server

ifeq ($(CI),true)
TEST_OPTS := -coverprofile=coverage.out
Expand Down Expand Up @@ -126,7 +127,7 @@ status:
# cli

.PHONY: cli
cli: dist/argo
cli: dist/argo argo-server.crt argo-server.key

ui/dist/node_modules.marker: ui/package.json ui/yarn.lock
# Get UI dependencies
Expand Down Expand Up @@ -154,20 +155,19 @@ server/static/files.go: $(HOME)/go/bin/staticfiles ui/dist/app/index.html
# Pack UI into a Go file.
staticfiles -o server/static/files.go ui/dist/app

dist/argo: server/static/files.go $(CLI_PKGS)
go build -v -i -ldflags '${LDFLAGS}' -o dist/argo ./cmd/argo

dist/argo-linux-amd64: GOARGS = GOOS=linux GOARCH=amd64
dist/argo-darwin-amd64: GOARGS = GOOS=darwin GOARCH=amd64
dist/argo-windows-amd64: GOARGS = GOOS=windows GOARCH=amd64
dist/argo-linux-arm64: GOARGS = GOOS=linux GOARCH=arm64
dist/argo-linux-ppc64le: GOARGS = GOOS=linux GOARCH=ppc64le
dist/argo-linux-s390x: GOARGS = GOOS=linux GOARCH=s390x

dist/argo: server/static/files.go $(CLI_PKGS)
go build -v -i -ldflags '${LDFLAGS}' -o dist/argo ./cmd/argo

dist/argo-%: server/static/files.go $(CLI_PKGS)
CGO_ENABLED=0 $(GOARGS) go build -v -i -ldflags '${LDFLAGS}' -o $@ ./cmd/argo


argo-server.crt: argo-server.key

argo-server.key:
Expand All @@ -176,46 +176,31 @@ argo-server.key:
.PHONY: cli-image
cli-image: $(CLI_IMAGE_FILE)

$(CLI_IMAGE_FILE): dist/argo-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH) argo-server.crt argo-server.key
# Create CLI image
ifeq ($(DEV_IMAGE),true)
cp dist/argo-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH) argo
docker build -t $(IMAGE_NAMESPACE)/argocli:$(VERSION) --target argocli -f Dockerfile.dev --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
rm -f argo
else
$(CLI_IMAGE_FILE):
docker build $(DOCKER_BUILD_OPTS) -t $(IMAGE_NAMESPACE)/argocli:$(VERSION) --target argocli --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
endif
ifeq ($(K3D),true)
k3d import-images $(IMAGE_NAMESPACE)/argocli:$(VERSION)
endif
touch $(CLI_IMAGE_FILE)

.PHONY: clis
clis: dist/argo-linux-amd64 dist/argo-linux-arm64 dist/argo-linux-ppc64le dist/argo-linux-s390x dist/argo-darwin-amd64 dist/argo-windows-amd64 cli-image

# controller
.PHONY: controller
controller: dist/workflow-controller

dist/workflow-controller: GOARGS = GOOS= GOARCH=
dist/workflow-controller-linux-amd64: GOARGS = GOOS=linux GOARCH=amd64
dist/workflow-controller-linux-arm64: GOARGS = GOOS=linux GOARCH=arm64

dist/workflow-controller: $(CONTROLLER_PKGS)
go build -v -i -ldflags '${LDFLAGS}' -o $@ ./cmd/workflow-controller

dist/workflow-controller-%: $(CONTROLLER_PKGS)
CGO_ENABLED=0 $(GOARGS) go build -v -i -ldflags '${LDFLAGS}' -o $@ ./cmd/workflow-controller

.PHONY: controller-image
controller-image: $(CONTROLLER_IMAGE_FILE)

$(CONTROLLER_IMAGE_FILE): dist/workflow-controller-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH)
# Create controller image
ifeq ($(DEV_IMAGE),true)
cp dist/workflow-controller-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH) workflow-controller
docker build -t $(IMAGE_NAMESPACE)/workflow-controller:$(VERSION) --target workflow-controller -f Dockerfile.dev --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
rm -f workflow-controller
else
$(CONTROLLER_IMAGE_FILE):
docker build $(DOCKER_BUILD_OPTS) -t $(IMAGE_NAMESPACE)/workflow-controller:$(VERSION) --target workflow-controller --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
endif
ifeq ($(K3D),true)
k3d import-images $(IMAGE_NAMESPACE)/workflow-controller:$(VERSION)
endif
touch $(CONTROLLER_IMAGE_FILE)

# argoexec
Expand All @@ -232,9 +217,9 @@ executor-image: $(EXECUTOR_IMAGE_FILE)
$(EXECUTOR_IMAGE_FILE): dist/argoexec-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH)
# Create executor image
ifeq ($(DEV_IMAGE),true)
cp dist/argoexec-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH) argoexec
mv dist/argoexec-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH) argoexec
docker build -t $(IMAGE_NAMESPACE)/argoexec:$(VERSION) --target argoexec -f Dockerfile.dev --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
rm -f argoexec
mv argoexec dist/argoexec-$(OUTPUT_IMAGE_OS)-$(OUTPUT_IMAGE_ARCH)
else
docker build $(DOCKER_BUILD_OPTS) -t $(IMAGE_NAMESPACE)/argoexec:$(VERSION) --target argoexec --build-arg IMAGE_OS=$(OUTPUT_IMAGE_OS) --build-arg IMAGE_ARCH=$(OUTPUT_IMAGE_ARCH) .
endif
Expand All @@ -251,12 +236,8 @@ $(HOME)/go/bin/mockery:
$(call restore_go_mod)

.PHONY: mocks
mocks: dist/update-mocks

dist/update-mocks: $(HOME)/go/bin/mockery $(MOCK_FILES)
mocks: $(HOME)/go/bin/mockery
./hack/update-mocks.sh $(MOCK_FILES)
@mkdir -p dist
touch dist/update-mocks

.PHONY: codegen
codegen: status codegen-core swagger mocks docs
Expand Down Expand Up @@ -325,14 +306,14 @@ $(VERSION_FILE):
touch $(VERSION_FILE)

dist/postgres.yaml: $(MANIFESTS) $(E2E_MANIFESTS) $(VERSION_FILE)
kustomize build --load_restrictor=none test/e2e/manifests/postgres | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/:E2E_TAG/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' > dist/postgres.yaml
kustomize build --load_restrictor=none test/e2e/manifests/postgres | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' > dist/postgres.yaml

dist/no-db.yaml: $(MANIFESTS) $(E2E_MANIFESTS) $(VERSION_FILE)
# We additionally disable ALWAYS_OFFLOAD_NODE_STATUS
kustomize build --load_restrictor=none test/e2e/manifests/no-db | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/:E2E_TAG/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' | sed 's/"true"/"false"/' > dist/no-db.yaml
kustomize build --load_restrictor=none test/e2e/manifests/no-db | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' | sed 's/"true"/"false"/' > dist/no-db.yaml

dist/mysql.yaml: $(MANIFESTS) $(E2E_MANIFESTS) $(VERSION_FILE)
kustomize build --load_restrictor=none test/e2e/manifests/mysql | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/:E2E_TAG/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' > dist/mysql.yaml
kustomize build --load_restrictor=none test/e2e/manifests/mysql | sed 's/:$(MANIFESTS_VERSION)/:$(VERSION)/' | sed 's/pns/$(E2E_EXECUTOR)/' > dist/mysql.yaml

.PHONY: install
install: dist/postgres.yaml dist/mysql.yaml dist/no-db.yaml
Expand Down Expand Up @@ -365,55 +346,53 @@ dist/python-alpine3.6:
docker pull python:alpine3.6
touch dist/python-alpine3.6

.PHONY: start
start: status install down controller-image cli-image executor-image wait-down up cli test-images wait-up env
# Switch to "argo" ns.
kubectl config set-context --current --namespace=argo
.PHONY: stop
stop:
killall argo workflow-controller pf.sh kubectl || true

.PHONY: run
run: start pf

.PHONY: down
down:
# Scale down
kubectl -n argo scale deployment/argo-server --replicas 0
kubectl -n argo scale deployment/workflow-controller --replicas 0

.PHONY: wait-down
wait-down:
# Wait for pods to go away, so we don't wait for them to be ready later.
[ "`kubectl -n argo get pod -l app=argo-server -o name`" = "" ] || kubectl -n argo wait --for=delete pod -l app=argo-server --timeout 30s
[ "`kubectl -n argo get pod -l app=workflow-controller -o name`" = "" ] || kubectl -n argo wait --for=delete pod -l app=workflow-controller --timeout 2m

.PHONY: up
up:
# Scale up
kubectl -n argo scale deployment/workflow-controller --replicas 1
kubectl -n argo scale deployment/argo-server --replicas 1

.PHONY: wait-up
wait-up:
# Wait for pods to be ready
.PHONY: start-aux
start-aux:
kubectl config set-context --current --namespace=argo
kubectl -n argo wait --for=condition=Ready pod --all -l app --timeout 2m
./hack/port-forward.sh
# Check minio, postgres and mysql are in hosts file
grep '127.0.0.1 *minio' /etc/hosts
grep '127.0.0.1 *postgres' /etc/hosts
grep '127.0.0.1 *mysql' /etc/hosts
ifneq ($(findstring controller,$(COMPONENTS)),)
ALWAYS_OFFLOAD_NODE_STATUS=true OFFLOAD_NODE_STATUS_TTL=30s WORKFLOW_GC_PERIOD=30s UPPERIO_DB_DEBUG=1 ARCHIVED_WORKFLOW_GC_PERIOD=30s ./dist/workflow-controller --executor-image argoproj/argoexec:$(VERSION) --namespaced --loglevel debug &
endif
ifneq ($(findstring argo-server,$(COMPONENTS)),)
UPPERIO_DB_DEBUG=1 ./dist/argo -v server --namespaced --auth-mode client --secure &
endif

.PHONY: start
start: status stop install controller cli executor-image start-aux wait env

.PHONY: wait
wait:
ifneq ($(findstring controller,$(COMPONENTS)),)
# Wait for workflow controller
until lsof -i :9090 > /dev/null ; do sleep 10s ; done
endif
ifneq ($(findstring argo-server,$(COMPONENTS)),)
# Wait for Argo Server
until lsof -i :2746 > /dev/null ; do sleep 10s ; done
endif

define print_env
export ARGO_SERVER=localhost:2746
export ARGO_SECURE=true
export ARGO_INSECURE_SKIP_VERIFY=true
export ARGO_TOKEN=$(shell ./dist/argo auth token)
endef

# this is a convenience to get the login token, you can use it as follows
# eval $(make env)
# argo token

.PHONY: env
env:
export ARGO_SERVER=localhost:2746
export ARGO_TOKEN=$(ARGO_TOKEN)

.PHONY: pf
pf:
# Start port-forwards
./hack/port-forward.sh

.PHONY: pf-bg
pf-bg:
# Start port-forwards in the background
./hack/port-forward.sh &
$(call print_env)

.PHONY: logs
logs:
Expand Down Expand Up @@ -461,8 +440,6 @@ test-cli: test-images cli

.PHONY: clean
clean:
# Delete pre-go 1.3 vendor
rm -Rf vendor
# Delete build files
rm -Rf dist/* ui/dist

Expand Down Expand Up @@ -500,7 +477,7 @@ docs: swagger
# pre-push

.PHONY: pre-commit
pre-commit: test lint codegen manifests start pf-bg smoke test-api test-cli
pre-commit: test lint codegen manifests start smoke test-api test-cli

# release - targets only available on release branch
ifneq ($(findstring release,$(GIT_BRANCH)),)
Expand Down
41 changes: 22 additions & 19 deletions docs/running-locally.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
Useful:

* For a PS1 prompt showing your current kube context: kube-ps1 to help. `brew install kube-ps1`
* For tailing logs: Stern. `brew install stern`

K3D tip: You can set-up K3D to be part of your default kube config as follows

cp ~/.kube/config ~/.kube/config.bak
cat $(k3d get-kubeconfig --name='k3s-default') >> ~/.kube/config

Add to /etc/hosts:

127.0.0.1 minio
127.0.0.1 postgres
127.0.0.1 mysql

To install into the “argo” namespace of your cluster: Argo, MinIO (for saving artifacts and logs) and Postgres (for offloading or archiving):

make start
Expand All @@ -27,13 +32,9 @@ If you prefer MySQL:

make start DB=mysql

To expose the services port forwards:

make pf

You’ll now have

* Argo on http:https://localhost:2746 (see below)
* Argo on https:https://localhost:2746
* MinIO https://localhost:9000 (use admin/password)

Either:
Expand All @@ -49,6 +50,8 @@ You need the token to access the CLI or UI:

At this point you’ll have everything you need to use the CLI and UI.

## User Interface

Tip: If you want to make UI changes without a time-consuming build:

cd ui
Expand All @@ -57,26 +60,25 @@ Tip: If you want to make UI changes without a time-consuming build:

The UI will start up on https://localhost:8080.

If you want to run controller or argo-server in your IDE (e.g. so you can debug it):

Add to /etc/hosts:

127.0.0.1 postgres
127.0.0.1 mysql
## Debugging

Scale down the services you want to debug:
If you want to run controller or argo-server in your IDE (e.g. so you can debug it):

kubectl -n argo scale deploy/workflow-controller --replicas 0
kubectl -n argo scale deploy/argo-server --replicas 0

Restart the port forwarding:
Start with only components you don't want to debug;

make pf
make start COMPONENTS=controller

Or

To find the command arguments you need to use, you’ll have to look at dist/postgres.yaml (or dist/mysql.yaml for MySQL aficionados).
make start COMPONENTS=argo-server

To find the command arguments you need to use, you’ll have to look at the `start` target in the `Makefile`.`

### Running Sonar Locally

This can only be done if you have already created a pull request.

Install the scanner:

```
Expand All @@ -101,5 +103,6 @@ SONAR_TOKEN=... sonar-scanner -Dsonar.pullrequest.key=... -Dsonar.pullrequest.br

To clean-up everything:

kubectl delete ns argo
make clean
kubectl delete ns argo
docker system prune -af
Loading

0 comments on commit c05c385

Please sign in to comment.