From 631ee96e9067a5846b64035dea9efa51a37c64c7 Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 2 Mar 2023 12:35:42 +0000 Subject: [PATCH] chore: opt out of panamax (#576) * chore: opt out of panamax * panamax link * fix link * feat: opt out of starting panamax container * fix: typos in contributing.md * refactor: skip panamax by default for make up * fix: make up override needs to go after `make` --------- Co-authored-by: oddgrd <29732646+oddgrd@users.noreply.github.com> --- CONTRIBUTING.md | 8 ++++++-- Containerfile | 3 ++- Makefile | 28 ++++++++++++++++++++-------- deployer/prepare.sh | 12 ++++++++++-- docker-compose.yml | 4 ++++ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4e0df5c89..51c8a8511 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,9 +29,11 @@ You should now be ready to setup a local environment to test code changes to cor From the root of the shuttle repo, build the required images with: ```bash -make images +USE_PANAMAX=disable make images ``` +> Note: The stack uses [panamax](https://github.com/panamax-rs/panamax) by default to mirror crates.io content. We do this in order to avoid overloading upstream mirrors and hitting rate limits. After syncing the cache, expect to see the panamax volume take about 100GiB of space. This may not be desirable for local testing. To avoid using panamax, run `USE_PANAMAX=disable make images` instead. + The images get built with [cargo-chef](https://github.com/LukeMathWalker/cargo-chef) and therefore support incremental builds (most of the time). So they will be much faster to re-build after an incremental change in your code - should you wish to deploy it locally straight away. You can now start a local deployment of shuttle and the required containers with: @@ -40,6 +42,8 @@ You can now start a local deployment of shuttle and the required containers with make up ``` +> Note: `make up` does not start [panamax](https://github.com/panamax-rs/panamax) by default, if you do need to start panamax for local development, run this command with `make COMPOSE_PROFILES=panamax up`. + > Note: Other useful commands can be found within the [Makefile](https://github.com/shuttle-hq/shuttle/blob/main/Makefile). The API is now accessible on `localhost:8000` (for app proxies) and `localhost:8001` (for the control plane). When running `cargo run --bin cargo-shuttle` (in a debug build), the CLI will point itself to `localhost` for its API calls. @@ -59,7 +63,7 @@ shuttle-static-folder = { path = "[base]/shuttle/resources/static-folder" } ``` Before we can login to our local instance of shuttle, we need to create a user. -The following command inserts a user into the gateway state with admin privileges: +The following command inserts a user into the `auth` state with admin privileges: ```bash docker compose --file docker-compose.rendered.yml --project-name shuttle-dev exec auth /usr/local/bin/service --state=/var/lib/shuttle-auth init --name admin --key test-key diff --git a/Containerfile b/Containerfile index c2a921825..0765cba36 100644 --- a/Containerfile +++ b/Containerfile @@ -37,8 +37,9 @@ COPY --from=cache /build/ /usr/src/shuttle/ FROM shuttle-common ARG folder +ARG prepare_args COPY ${folder}/prepare.sh /prepare.sh -RUN /prepare.sh +RUN /prepare.sh "${prepare_args}" ARG CARGO_PROFILE COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service ARG RUSTUP_TOOLCHAIN diff --git a/Makefile b/Makefile index 855946abd..2bed9be28 100644 --- a/Makefile +++ b/Makefile @@ -72,7 +72,13 @@ PANAMAX_TAG?=1.0.12 OTEL_EXTRA_PATH?=./extras/otel OTEL_TAG?=0.72.0 -DOCKER_COMPOSE_ENV=STACK=$(STACK) BACKEND_TAG=$(BACKEND_TAG) DEPLOYER_TAG=$(DEPLOYER_TAG) PROVISIONER_TAG=$(PROVISIONER_TAG) POSTGRES_TAG=${POSTGRES_TAG} PANAMAX_TAG=${PANAMAX_TAG} OTEL_TAG=${OTEL_TAG} APPS_FQDN=$(APPS_FQDN) DB_FQDN=$(DB_FQDN) POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) RUST_LOG=$(RUST_LOG) CONTAINER_REGISTRY=$(CONTAINER_REGISTRY) MONGO_INITDB_ROOT_USERNAME=$(MONGO_INITDB_ROOT_USERNAME) MONGO_INITDB_ROOT_PASSWORD=$(MONGO_INITDB_ROOT_PASSWORD) DD_ENV=$(DD_ENV) USE_TLS=$(USE_TLS) +USE_PANAMAX?=enable +ifeq ($(USE_PANAMAX), enable) +PREPARE_ARGS+=-p +COMPOSE_PROFILES+=panamax +endif + +DOCKER_COMPOSE_ENV=STACK=$(STACK) BACKEND_TAG=$(BACKEND_TAG) DEPLOYER_TAG=$(DEPLOYER_TAG) PROVISIONER_TAG=$(PROVISIONER_TAG) POSTGRES_TAG=${POSTGRES_TAG} PANAMAX_TAG=${PANAMAX_TAG} OTEL_TAG=${OTEL_TAG} APPS_FQDN=$(APPS_FQDN) DB_FQDN=$(DB_FQDN) POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) RUST_LOG=$(RUST_LOG) CONTAINER_REGISTRY=$(CONTAINER_REGISTRY) MONGO_INITDB_ROOT_USERNAME=$(MONGO_INITDB_ROOT_USERNAME) MONGO_INITDB_ROOT_PASSWORD=$(MONGO_INITDB_ROOT_PASSWORD) DD_ENV=$(DD_ENV) USE_TLS=$(USE_TLS) COMPOSE_PROFILES=$(COMPOSE_PROFILES) .PHONY: images clean src up down deploy shuttle-% postgres docker-compose.rendered.yml test bump-% deploy-examples publish publish-% --validate-version @@ -91,12 +97,14 @@ postgres: $(POSTGRES_EXTRA_PATH) panamax: - docker buildx build \ - --build-arg PANAMAX_TAG=$(PANAMAX_TAG) \ - --tag $(CONTAINER_REGISTRY)/panamax:$(PANAMAX_TAG) \ - $(BUILDX_FLAGS) \ - -f $(PANAMAX_EXTRA_PATH)/Containerfile \ - $(PANAMAX_EXTRA_PATH) + if [ $(USE_PANAMAX) = "enable" ]; then \ + docker buildx build \ + --build-arg PANAMAX_TAG=$(PANAMAX_TAG) \ + --tag $(CONTAINER_REGISTRY)/panamax:$(PANAMAX_TAG) \ + $(BUILDX_FLAGS) \ + -f $(PANAMAX_EXTRA_PATH)/Containerfile \ + $(PANAMAX_EXTRA_PATH); \ + fi otel: docker buildx build \ @@ -115,6 +123,9 @@ deploy: docker-compose.yml test: cd e2e; POSTGRES_PASSWORD=$(POSTGRES_PASSWORD) APPS_FQDN=$(APPS_FQDN) cargo test $(CARGO_TEST_FLAGS) -- --nocapture +# Start the containers locally. This does not start panamax by default, +# to start panamax locally run this command with the COMPOSE_PROFILES=panamax +# environment variable. up: docker-compose.rendered.yml CONTAINER_REGISTRY=$(CONTAINER_REGISTRY) $(DOCKER_COMPOSE) -f $< -p $(STACK) up -d $(DOCKER_COMPOSE_FLAGS) @@ -124,7 +135,8 @@ down: docker-compose.rendered.yml shuttle-%: ${SRC} Cargo.lock docker buildx build \ --build-arg folder=$(*) \ - --build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \ + --build-arg prepare_args=$(PREPARE_ARGS) \ + --build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \ --build-arg CARGO_PROFILE=$(CARGO_PROFILE) \ --tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \ --tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \ diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 70eac8a23..38a848028 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -15,12 +15,20 @@ shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" } shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" } shuttle-static-folder = { path = "/usr/src/shuttle/resources/static-folder" }' > $CARGO_HOME/config.toml -# Make future crates requests to our own mirror -echo ' +while getopts "p," o; do + case $o in + "p") + # Make future crates requests to our own mirror + echo ' [source.shuttle-crates-io-mirror] registry = "http://panamax:8080/git/crates.io-index" [source.crates-io] replace-with = "shuttle-crates-io-mirror"' >> $CARGO_HOME/config.toml + ;; + *) + ;; + esac +done # Prefetch crates.io index from our mirror # TODO: restore when we know how to prefetch from our mirror diff --git a/docker-compose.yml b/docker-compose.yml index 85ef0e204..6fffc6dec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -173,6 +173,8 @@ services: constraints: - node.hostname==controller panamax: + profiles: + - panamax image: "${CONTAINER_REGISTRY}/panamax:${PANAMAX_TAG}" restart: always networks: @@ -189,6 +191,8 @@ services: constraints: - node.hostname==controller deck-chores: + profiles: + - panamax image: funkyfuture/deck-chores:1 restart: unless-stopped environment: