Skip to content

Commit 43716a8

Browse files
committed
feat: make execution of 'setup' container manual
Closes #798
1 parent 41204d8 commit 43716a8

File tree

7 files changed

+18
-53
lines changed

7 files changed

+18
-53
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ jobs:
6464
##########################################################
6565

6666
- name: Run the stack
67-
run: docker compose up -d
67+
run: |
68+
docker compose up setup
69+
docker compose up -d
6870
6971
- name: Execute core test suite
7072
run: .github/workflows/scripts/run-tests-core.sh

README.md

+2-18
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,9 @@ own_. [sherifabdlnaby/elastdocker][elastdocker] is one example among others of p
9191
### Host setup
9292

9393
* [Docker Engine][docker-install] version **18.06.0** or newer
94-
* [Docker Compose][compose-install] version **1.26.0** or newer (including [Compose V2][compose-v2])
94+
* [Docker Compose][compose-install] version **1.28.0** or newer (including [Compose V2][compose-v2])
9595
* 1.5 GB of RAM
9696

97-
> **Warning**
98-
> While Compose versions between **1.22.0** and **1.25.5** can technically run this stack as well, these versions have a
99-
> [known issue](https://github.com/deviantony/docker-elk/pull/678#issuecomment-1055555368) which prevents them from
100-
> parsing quoted values properly inside `.env` files.
101-
10297
> **Note**
10398
> Especially on Linux, make sure your user has the [required permissions][linux-postinstall] to interact with the Docker
10499
> daemon.
@@ -357,21 +352,10 @@ Follow the instructions from the Wiki: [Scaling out Elasticsearch](https://githu
357352
### How to re-execute the setup
358353

359354
To run the setup container again and re-initialize all users for which a password was defined inside the `.env` file,
360-
delete its volume and "up" the `setup` Compose service again manually:
361-
362-
```console
363-
$ docker-compose rm -f setup
364-
⠿ Container docker-elk-setup-1 Removed
365-
```
366-
367-
```console
368-
$ docker volume rm docker-elk_setup
369-
docker-elk_setup
370-
```
355+
simply "up" the `setup` Compose service again:
371356

372357
```console
373358
$ docker-compose up setup
374-
⠿ Volume "docker-elk_setup" Created
375359
⠿ Container docker-elk-elasticsearch-1 Running
376360
⠿ Container docker-elk-setup-1 Created
377361
Attaching to docker-elk-setup-1

docker-compose.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ services:
44

55
# The 'setup' service runs a one-off script which initializes users inside
66
# Elasticsearch — such as 'logstash_internal' and 'kibana_system' — with the
7-
# values of the passwords defined in the '.env' file.
7+
# values of the passwords defined in the '.env' file. It also creates the
8+
# roles required by some of these users.
89
#
9-
# This task is only performed during the *initial* startup of the stack. On all
10-
# subsequent runs, the service simply returns immediately, without performing
11-
# any modification to existing users.
10+
# This task only needs to be performed once, during the *initial* startup of
11+
# the stack. Any subsequent run will reset the passwords of existing users to
12+
# the values defined inside the '.env' file, and the built-in roles to their
13+
# default permissions.
14+
#
15+
# By default, it is excluded from the services started by 'docker compose up'
16+
# due to the non-default profile it belongs to. To run it, either provide the
17+
# '--profile=setup' CLI flag to Compose commands, or "up" the service by name
18+
# such as 'docker compose up setup'.
1219
setup:
20+
profiles:
21+
- setup
1322
build:
1423
context: setup/
1524
args:
@@ -19,7 +28,6 @@ services:
1928
- ./setup/entrypoint.sh:/entrypoint.sh:ro,Z
2029
- ./setup/lib.sh:/lib.sh:ro,Z
2130
- ./setup/roles:/roles:ro,Z
22-
- setup:/state:Z
2331
environment:
2432
ELASTIC_PASSWORD: ${ELASTIC_PASSWORD:-}
2533
LOGSTASH_INTERNAL_PASSWORD: ${LOGSTASH_INTERNAL_PASSWORD:-}
@@ -103,5 +111,4 @@ networks:
103111
driver: bridge
104112

105113
volumes:
106-
setup:
107114
elasticsearch:

setup/.dockerignore

-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,3 @@ Dockerfile
77

88
# Ignore Git files
99
.gitignore
10-
11-
# Ignore setup state
12-
state/

setup/.gitignore

-1
This file was deleted.

setup/Dockerfile

-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,4 @@ ARG ELASTIC_VERSION
33
# https://www.docker.elastic.co/
44
FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION}
55

6-
USER root
7-
8-
RUN set -eux; \
9-
mkdir /state; \
10-
chmod 0775 /state; \
11-
chown elasticsearch:root /state
12-
13-
USER elasticsearch:root
14-
156
ENTRYPOINT ["/entrypoint.sh"]

setup/entrypoint.sh

-15
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ roles_files=(
4343
# --------------------------------------------------------
4444

4545

46-
echo "-------- $(date --rfc-3339=seconds) --------"
47-
48-
state_file="${BASH_SOURCE[0]%/*}"/state/.done
49-
if [[ -e "$state_file" ]]; then
50-
declare state_birthtime
51-
state_birthtime="$(stat -c '%Y' "$state_file")"
52-
state_birthtime="$(date --rfc-3339=seconds --date="@${state_birthtime}")"
53-
54-
log "Setup has already run successfully on ${state_birthtime}. Skipping"
55-
exit 0
56-
fi
57-
5846
log 'Waiting for availability of Elasticsearch. This can take several minutes.'
5947

6048
declare -i exit_code=0
@@ -129,6 +117,3 @@ for user in "${!users_passwords[@]}"; do
129117
create_user "$user" "${users_passwords[$user]}" "${users_roles[$user]}"
130118
fi
131119
done
132-
133-
mkdir -p "${state_file%/*}"
134-
touch "$state_file"

0 commit comments

Comments
 (0)