Skip to content

Commit

Permalink
Adjust configuration to Docker Compose V2 (#186)
Browse files Browse the repository at this point in the history
This patch replaces uses of `docker-compose` with `docker compose`. If
the new command doesn't exist we still fall back to `docker-compose`.
  • Loading branch information
fredrikekre authored Dec 29, 2023
1 parent c122c0a commit 5324cb1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ $ JULIA_PKG_SERVER=http://localhost:8000 julia

## Deployment

See the [deployment](deployment) directory for an example `docker-compose` setup to easily deploy your own mirror Pkg server, with an optional SSL interface provided through `nginx` and `letsencrypt`.
See the [deployment](deployment) directory for an example `docker compose` setup to easily deploy your own mirror Pkg server, with an optional SSL interface provided through `nginx` and `letsencrypt`.
21 changes: 12 additions & 9 deletions deployment/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Default target is to bring everything up
all: up

# Use docker compose if it exist, fall back to docker-compose
COMPOSE=$(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)

# Extract configuration from `.env` file
PKG_SERVER_REGION := $(shell bash -c "source .env 2>/dev/null && echo \$$PKG_SERVER_REGION")
ifeq ($(PKG_SERVER_REGION),)
Expand Down Expand Up @@ -60,13 +63,13 @@ build/pkgserver.nginx.conf: conf/pkgserver.nginx.conf ${LISTEN_SRC} | build
envsubst '$${LISTEN_BLOCK_SRC} $${LISTEN_BLOCK} $${MIRROR_BLOCK} $${REGION} $${FQDN}' < $< > $@

up: $(DIRS) build/pkgserver.nginx.conf
docker-compose up --build --remove-orphans -d
${COMPOSE} up --build --remove-orphans -d

down:
docker-compose down --remove-orphans
${COMPOSE} down --remove-orphans

pull:
docker-compose pull
${COMPOSE} pull

# Rule to install logrotate configuration so that host-wide logrotate can
# perform the logrotations, as well as run `make nginx-send-usr1`.
Expand All @@ -84,9 +87,9 @@ include logrotate.make
sudo chmod +x $@
up: /etc/cron.hourly/pkgserver

# Rule to send nginx USR1 signal via docker-compose (used by `logrotate.conf`)
# Rule to send nginx USR1 signal via docker compose (used by `logrotate.conf`)
nginx-send-usr1:
docker-compose exec -T frontend /bin/bash -c 'kill -USR1 `pgrep -f "nginx: [m]aster"`'
${COMPOSE} exec -T frontend /bin/bash -c 'kill -USR1 `pgrep -f "nginx: [m]aster"`'

/etc/cron.daily/pkgserver: conf/cron.restart.conf
SOURCEDIR=$(shell pwd) PYTHONPATH=$(PYTHONPATH) UID=$(UID) GID=$(GID) envsubst < $< | sudo tee $@ >/dev/null
Expand All @@ -109,17 +112,17 @@ dev-up:


stop-watchtower:
docker-compose stop watchtower
${COMPOSE} stop watchtower

trigger-watchtower:
docker-compose run --rm watchtower --cleanup --scope pkgserver.jl --run-once
${COMPOSE} run --rm watchtower --cleanup --scope pkgserver.jl --run-once

logs:
docker-compose logs -f --tail=100
${COMPOSE} logs -f --tail=100
.PHONY: logs

destroy:
docker-compose down -v --remove-orphans
${COMPOSE} down -v --remove-orphans
rm -rf logs storage build
sudo rm -f /etc/cron.hourly/pkgserver /etc/cron.daily/pkgserver

Expand Down
2 changes: 1 addition & 1 deletion deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Deployment of a new PkgServer is as easy as filling out a `.env` file and running `make`. The `.env` file controls the customization of the PkgServer and associated containers. The values that should be set are listed in `.env.example`, along with whether the value is required or not. There are two separate `docker-compose.yml` configurations listed here; a non-SSL version, and an SSL version. The non-SSL version just runs the pkg server directly on port `8000`, while the SSL version runs an `nginx` SSL terminator (hooked up with `letsencrypt`), then `proxy_pass`'es the decrypted traffic to a PkgServer instance running within a separate container.

To avoid needing to memorize arcane `docker-compose` commands, a handy `Makefile` is provided to ease usage of `docker-compose`. Valid make verbs are `up`, `build`, `logs`, `down`, `destroy`, etc.... By default, the non-SSL version will be deployed, to build/deploy the SSL version, invoke `make` with the `USE_SSL=1` flag.
To avoid needing to memorize arcane `docker compose` commands, a handy `Makefile` is provided to ease usage of `docker compose`. Valid make verbs are `up`, `build`, `logs`, `down`, `destroy`, etc.... By default, the non-SSL version will be deployed, to build/deploy the SSL version, invoke `make` with the `USE_SSL=1` flag.

The deployment also includes a [`watchtower`](https://github.com/containrrr/watchtower) listener that polls Docker Hub for updated versions of the [`juliapackaging/pkgserver.jl`](https://hub.docker.com/r/juliapackaging/pkgserver.jl) image every 5 minutes. When a new version is discovered, it is automatically pulled down. This forms the basis of our automatic deployment pipeline; as a PR is merged within this repository, it will trigger a new build of the `pkgserver.jl` docker image, which then gets downloaded by any and all deployments within a matter of minutes. In the event of catastrophic server failure (e.g. a bug slips past and the PkgServer cannot start) pushing a new version should robustly upgrade, as the `watchtower` image is separated from the `pkgserver` process.
1 change: 0 additions & 1 deletion deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
- ./logs/pkgserver:/app/logs
environment:
JULIA_PKG_SERVER: "0.0.0.0:8000"
JULIA_PKG_SERVER_STORAGE_SERVERS: "https://us-east.storage.juliahub.com,https://kr.storage.juliahub.com"
JULIA_PKG_SERVER_STORAGE_ROOT: "/app/storage"
JULIA_PKG_SERVER_LOGS_DIR: "/app/logs"
JULIA_PKG_SERVER_FQDN: "${PKG_SERVER_FQDN}"
Expand Down
17 changes: 10 additions & 7 deletions loadbalancer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ all: up
COMMA:=,
SPACE:=$(eval) $(eval)

# Use docker compose if it exist, fall back to docker-compose
COMPOSE=$(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)

# Extract configuration from `.env` file
SERVER_REGION := $(shell bash -c "source .env 2>/dev/null && echo \$$SERVER_REGION")
PKGSERVERS := $(shell bash -c "source .env 2>/dev/null && echo \$$PKGSERVERS")
Expand Down Expand Up @@ -33,10 +36,10 @@ build/children.json: .env | build
up: build/children.json

up: $(DIRS) build/loadbalancer.nginx.conf
docker-compose up --build --remove-orphans -d
${COMPOSE} up --build --remove-orphans -d

down:
docker-compose down --remove-orphans
${COMPOSE} down --remove-orphans

# Rule to install logrotate configuration so that host-wide logrotate can
# perform the logrotations, as well as run `make nginx-send-usr1`.
Expand All @@ -54,19 +57,19 @@ up: /etc/cron.hourly/loadbalancer

include ../deployment/logrotate.make

# Rule to send nginx USR1 signal via docker-compose (used by `logrotate.conf`)
# Rule to send nginx USR1 signal via docker compose (used by `logrotate.conf`)
nginx-send-usr1:
docker-compose exec -T loadbalancer /bin/bash -c 'kill -USR1 `pgrep -f "nginx: [m]aster"`'
${COMPOSE} exec -T loadbalancer /bin/bash -c 'kill -USR1 `pgrep -f "nginx: [m]aster"`'

stop-watchtower:
docker-compose stop watchtower
${COMPOSE} stop watchtower

logs:
docker-compose logs -f --tail=100
${COMPOSE} logs -f --tail=100
.PHONY: logs

destroy:
docker-compose down -v --remove-orphans
${COMPOSE} down -v --remove-orphans
rm -rf logs build

restart:
Expand Down
7 changes: 5 additions & 2 deletions test/perf/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))

# Use docker compose if it exist, fall back to docker-compose
COMPOSE=$(shell if docker compose version >/dev/null 2>&1; then echo "docker compose"; else echo "docker-compose"; fi)

K6 := docker run --rm -v $(SRCDIR):/config:ro -v $(SRCDIR)/results:/results --net=host -ti loadimpact/k6

up:
docker-compose up -d --remove-orphans
${COMPOSE} up -d --remove-orphans

down:
docker-compose down -v --remove-orphans
${COMPOSE} down -v --remove-orphans

results:
mkdir -p $@
Expand Down

0 comments on commit 5324cb1

Please sign in to comment.