Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move to correctly namespaced labels #1046

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
test-name:
[
docker_api,
docker_api_legacy,
location_config,
certs_single,
certs_san,
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.docker
.vscode
certs/
conf.d/
data/
vhost.d/
.vscode

# tests
go/
Expand Down
4 changes: 2 additions & 2 deletions app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ if [[ "$*" == "/bin/bash /app/start.sh" ]]; then
echo "Check that you are doing one of the following :" >&2
echo -e "\t- Use the --volumes-from option to mount volumes from the nginx-proxy container." >&2
echo -e "\t- Set the NGINX_PROXY_CONTAINER env var on the letsencrypt-companion container to the name of the nginx-proxy container." >&2
echo -e "\t- Label the nginx-proxy container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy'." >&2
echo -e "\t- Label the nginx-proxy container to use with 'com.github.nginx-proxy.nginx'." >&2
exit 1
elif [[ -z "$(get_docker_gen_container)" ]] && ! is_docker_gen_container "$(get_nginx_proxy_container)"; then
echo "Error: can't get docker-gen container id !" >&2
echo "If you are running a three containers setup, check that you are doing one of the following :" >&2
echo -e "\t- Set the NGINX_DOCKER_GEN_CONTAINER env var on the letsencrypt-companion container to the name of the docker-gen container." >&2
echo -e "\t- Label the docker-gen container to use with 'com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen'." >&2
echo -e "\t- Label the docker-gen container to use with 'com.github.nginx-proxy.docker-gen'." >&2
exit 1
fi
check_writable_directory '/etc/nginx/certs'
Expand Down
8 changes: 6 additions & 2 deletions app/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ function is_docker_gen_container {

function get_docker_gen_container {
# First try to get the docker-gen container ID from the container label.
local docker_gen_cid; docker_gen_cid="$(labeled_cid com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen)"
local legacy_docker_gen_cid; legacy_docker_gen_cid="$(labeled_cid com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen)"
local new_docker_gen_cid; new_docker_gen_cid="$(labeled_cid com.github.nginx-proxy.docker-gen)"
local docker_gen_cid; docker_gen_cid="${new_docker_gen_cid:-$legacy_docker_gen_cid}"

# If the labeled_cid function dit not return anything and the env var is set, use it.
if [[ -z "$docker_gen_cid" ]] && [[ -n "${NGINX_DOCKER_GEN_CONTAINER:-}" ]]; then
Expand All @@ -292,7 +294,9 @@ function get_docker_gen_container {
function get_nginx_proxy_container {
local volumes_from
# First try to get the nginx container ID from the container label.
local nginx_cid; nginx_cid="$(labeled_cid com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy)"
local legacy_nginx_cid; legacy_nginx_cid="$(labeled_cid com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy)"
local new_nginx_cid; new_nginx_cid="$(labeled_cid com.github.nginx-proxy.nginx)"
local nginx_cid; nginx_cid="${new_nginx_cid:-$legacy_nginx_cid}"

# If the labeled_cid function dit not return anything ...
if [[ -z "${nginx_cid}" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion docs/Advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Please read and try [basic usage](./Basic-usage.md), and **validate that you hav
curl https://raw.githubusercontent.com/nginx-proxy/nginx-proxy/main/nginx.tmpl > /path/to/nginx.tmpl
```

2) Use the `com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen` label on the **docker-gen** container, or explicitly set the `NGINX_DOCKER_GEN_CONTAINER` environment variable on the **acme-companion** container to the name or id of the **docker-gen** container (we'll use the later method in the example).
2) Use the `com.github.nginx-proxy.docker-gen` label on the **docker-gen** container, or explicitly set the `NGINX_DOCKER_GEN_CONTAINER` environment variable on the **acme-companion** container to the name or id of the **docker-gen** container (we'll use the later method in the example).

3) Declare `/etc/nginx/conf.d` as a volume on the nginx container so that it can be shared with the **docker-gen** container.

Expand Down
2 changes: 1 addition & 1 deletion docs/Docker-Compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ services:
- /path/to/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen"
- "com.github.nginx-proxy.docker-gen"
network_mode: bridge

acme-companion:
Expand Down
10 changes: 5 additions & 5 deletions docs/Getting-containers-IDs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ For **acme-companion** to work properly, it needs to know the ID of the **nginx*

There are three methods to inform the **acme-companion** container of the **nginx**/**nginx-proxy** container ID:

* `label` method: add the label `com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy` to the **nginx**/**nginx-proxy** container.
* `label` method: add the label `com.github.nginx-proxy.nginx` to the **nginx**/**nginx-proxy** container.

* `environment variable` method: assign a fixed name to the **nginx**/**nginx-proxy** container with `container_name:` and set the environment variable `NGINX_PROXY_CONTAINER` to this name on the **acme-companion** container.

* `volumes_from` method. Using this method, the **acme-companion** container will get the **nginx**/**nginx-proxy** container ID from the volumes it got using the `volumes_from` option.

And two methods to inform the **acme-companion** container of the **docker-gen** container ID:

* `label` method: add the label `com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen` to the **docker-gen** container.
* `label` method: add the label `com.github.nginx-proxy.docker-gen` to the **docker-gen** container.

* `environment variable` method: assign a fixed name to the **docker-gen** container with `container_name:` and set the environment variable `NGINX_DOCKER_GEN_CONTAINER` to this name on the **acme-companion** container.

Expand All @@ -26,12 +26,12 @@ The advantage the `label` methods have over the `environment variable` (and `vol
```
$ docker run --detach \
[...]
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
--label com.github.nginx-proxy.nginx \
nginx

$ docker run --detach \
[...]
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen \
--label com.github.nginx-proxy.docker-gen \
nginxproxy/docker-gen

$ docker run --detach \
Expand Down Expand Up @@ -67,7 +67,7 @@ $ docker run --detach \

$ docker run --detach \
[...]
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen \
--label com.github.nginx-proxy.docker-gen \
nginxproxy/docker-gen

$ docker run --detach \
Expand Down
1 change: 1 addition & 0 deletions test/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

globalTests+=(
docker_api
docker_api_legacy
location_config
default_cert
certs_single
Expand Down
2 changes: 1 addition & 1 deletion test/setup/setup-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ EOF
get_environment

# Stop and remove nginx-proxy and (if required) docker-gen
for cid in $(docker ps -a --filter "label=com.github.jrcs.letsencrypt_nginx_proxy_companion.test_suite" --format "{{.ID}}"); do
for cid in $(docker ps -a --filter "label=com.github.nginx-proxy.acme-companion.test-suite" --format "{{.ID}}"); do
docker stop "$cid"
docker rm --volumes "$cid"
done
Expand Down
6 changes: 3 additions & 3 deletions test/setup/setup-nginx-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ case $SETUP in
-v /etc/nginx/vhost.d \
-v /usr/share/nginx/html \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.test_suite \
--label com.github.nginx-proxy.acme-companion.test-suite \
--network "$test_net" \
nginxproxy/nginx-proxy
;;
Expand All @@ -42,7 +42,7 @@ case $SETUP in
-v /etc/nginx/conf.d \
-v /etc/nginx/vhost.d \
-v /usr/share/nginx/html \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.test_suite \
--label com.github.nginx-proxy.acme-companion.test-suite \
--network "$test_net" \
nginx:alpine

Expand All @@ -51,7 +51,7 @@ case $SETUP in
--volumes-from "$NGINX_CONTAINER_NAME" \
-v "${GITHUB_WORKSPACE}/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro" \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.test_suite \
--label com.github.nginx-proxy.acme-companion.test-suite \
--network "$test_net" \
nginxproxy/docker-gen \
-notify-sighup "$NGINX_CONTAINER_NAME" -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
Expand Down
8 changes: 4 additions & 4 deletions test/tests/docker_api/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ case $SETUP in
labeled_nginx_cid="$(docker run --rm -d \
--name "$nginx_lbl" \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
--label com.github.nginx-proxy.nginx \
nginxproxy/nginx-proxy)"

# This should target the nginx-proxy container with the label (nginx-label)
Expand Down Expand Up @@ -156,7 +156,7 @@ EOF
# Spawn a nginx container named nginx-label, with the nginx_proxy label.
labeled_nginx1_cid="$(docker run --rm -d \
--name "$nginx_lbl" \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
--label com.github.nginx-proxy.nginx \
nginx:alpine)"

# This should target the nginx container whose id or name was obtained with
Expand All @@ -176,7 +176,7 @@ EOF
# Spawn a "fake docker-gen" container named docker-gen-label, with the docker_gen label.
labeled_docker_gen_cid="$(docker run --rm -d \
--name "$docker_gen_lbl" \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen \
--label com.github.nginx-proxy.docker-gen \
nginx:alpine)"

# This should target the nginx container whose id or name was obtained with
Expand Down Expand Up @@ -205,7 +205,7 @@ EOF
# Spawn a nginx container named nginx-label, with the nginx_proxy label.
labeled_nginx2_cid="$(docker run --rm -d \
--name "$nginx_lbl" \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \
--label com.github.nginx-proxy.nginx \
nginx:alpine)"

# This should target the nginx container whose id or name was obtained with
Expand Down
Loading