Skip to content

Commit 0610fef

Browse files
committed
feat: devcontainer compose
1 parent 8c35242 commit 0610fef

28 files changed

+858
-303
lines changed

.devcontainer/Dockerfiles/Dockerfile-Alma-8

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM almalinux:8
2+
ARG TZ
23
RUN dnf update -y && \
34
dnf install -y \
45
dnf-utils \
@@ -10,6 +11,10 @@ RUN dnf update -y && \
1011
openssh-clients \
1112
openssh-server \
1213
&& dnf clean all
13-
ENV TZ='Europe/Berlin'
14-
RUN mkdir -p /run/sshd && ssh-keygen -A
14+
ENV TZ=${TZ:-Europe/Berlin}
15+
RUN mkdir -p /run/sshd && ssh-keygen -A \
16+
&& install --directory --mode=0700 /root/.ssh \
17+
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
18+
COPY ./ssh-keys/clients/authorized_keys /root/.ssh/authorized_keys
19+
RUN chown $(id -u):$(id -g) /root/.ssh/authorized_keys && chmod 644 /root/.ssh/authorized_keys
1520
CMD ["/usr/sbin/sshd", "-D"]

.devcontainer/Dockerfiles/Dockerfile-Debian-12

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:slim-bookworm
2+
ARG TZ
3+
RUN apt update && \
4+
export DEBIAN_FRONTEND=noninteractive && \
5+
apt install -y --no-install-recommends \
6+
dialog \
7+
apt-utils \
8+
sudo \
9+
curl \
10+
tzdata \
11+
iproute2 \
12+
python3 \
13+
openssh-server \
14+
&& rm -rf /var/lib/apt/lists/*
15+
ENV TZ=${TZ:-Europe/Berlin}
16+
RUN mkdir -p /run/sshd && ssh-keygen -A \
17+
&& install --directory --mode=0700 /root/.ssh \
18+
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
19+
COPY ./ssh-keys/clients/authorized_keys /root/.ssh/authorized_keys
20+
RUN chown $(id -u):$(id -g) /root/.ssh/authorized_keys && chmod 644 /root/.ssh/authorized_keys
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM local/debian-12-base
2+
CMD ["/usr/sbin/sshd", "-D"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM local/debian-12-base
2+
3+
ARG ANSIBLE_VERSION
4+
ARG ANSIBLE_LINT_VERSION
5+
6+
COPY ./scripts/setup-docker-container.sh /tmp
7+
8+
RUN chmod +x /tmp/setup-docker-container.sh && \
9+
/tmp/setup-docker-container.sh install all ansible ${ANSIBLE_VERSION} ${ANSIBLE_LINT_VERSION}
10+
11+
# CMD ["/usr/sbin/sshd", "-D"]
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM opensuse/leap:15
2+
ARG TZ
23
RUN zypper update -y && \
34
zypper install -y \
45
sudo \
@@ -8,6 +9,10 @@ RUN zypper update -y && \
89
openssh-clients \
910
openssh-server \
1011
&& zypper clean -a
11-
ENV TZ='Europe/Berlin'
12-
RUN mkdir -p /run/sshd && ssh-keygen -A
12+
ENV TZ=${TZ:-Europe/Berlin}
13+
RUN mkdir -p /run/sshd && ssh-keygen -A \
14+
&& install --directory --mode=0700 /root/.ssh \
15+
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
16+
COPY ./ssh-keys/clients/authorized_keys /root/.ssh/authorized_keys
17+
RUN chown $(id -u):$(id -g) /root/.ssh/authorized_keys && chmod 644 /root/.ssh/authorized_keys
1318
CMD ["/usr/sbin/sshd", "-D"]

.devcontainer/Dockerfiles/Dockerfile-Ubuntu-22.04 renamed to .devcontainer/Dockerfiles/Dockerfile-Ubuntu-2204

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM ubuntu:22.04
2+
ARG TZ
23
RUN sed -i 's,http://archive,http://de.archive,' /etc/apt/sources.list
34
RUN apt update && \
45
export DEBIAN_FRONTEND=noninteractive && \
@@ -12,6 +13,10 @@ RUN apt update && \
1213
python3 \
1314
openssh-server \
1415
&& rm -rf /var/lib/apt/lists/*
15-
ENV TZ='Europe/Berlin'
16-
RUN mkdir -p /run/sshd && ssh-keygen -A
16+
ENV TZ=${TZ:-Europe/Berlin}
17+
RUN mkdir -p /run/sshd && ssh-keygen -A \
18+
&& install --directory --mode=0700 /root/.ssh \
19+
&& echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
20+
COPY ./ssh-keys/clients/authorized_keys /root/.ssh/authorized_keys
21+
RUN chown $(id -u):$(id -g) /root/.ssh/authorized_keys && chmod 644 /root/.ssh/authorized_keys
1722
CMD ["/usr/sbin/sshd", "-D"]

.devcontainer/devcontainer.json

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
22
// README at: https://github.com/devcontainers/templates/tree/main/src/python
33
{
4-
"name": "Ansible-Debian-12",
5-
"initializeCommand": "bash ./.devcontainer/scripts/initialize-command.sh",
6-
"image": "mcr.microsoft.com/devcontainers/python:3-bookworm",
7-
"runArgs": [
8-
"--name=ansible-playground-control",
9-
"--hostname=ansible-control",
10-
"--network=ansible-playground"
4+
"name": "Ansible-Playground",
5+
"dockerComposeFile": [
6+
"docker-compose.yml",
7+
"docker-compose.dev.yml"
118
],
12-
"containerEnv": {
13-
"TZ": "Europe/Berlin"
14-
},
9+
"service": "ansible-control",
10+
"workspaceFolder": "/workspace/ansible-playground",
11+
"initializeCommand": "bash ./.devcontainer/scripts/initialize-command.sh",
12+
"onCreateCommand": "bash ./.devcontainer/scripts/on-create-command.sh",
13+
"postCreateCommand": "bash ./.devcontainer/scripts/post-create-command.sh",
14+
"remoteUser": "vscode",
1515
// Features to add to the dev container. More info: https://containers.dev/features.
1616
"features": {
17-
"ghcr.io/devcontainers/features/sshd:1": {}
17+
"ghcr.io/devcontainers/features/sshd:1": {},
18+
"ghcr.io/devcontainers/features/common-utils": {
19+
"username": "vscode",
20+
"userUid": 1000,
21+
"userGid": 1000,
22+
"installZsh": false,
23+
"installOhMyZsh": false,
24+
"configureZshAsDefaultShell": false,
25+
"installOhMyZshConfig": false
26+
}
1827
},
1928
// Configure tool-specific properties.
2029
"customizations": {
@@ -36,7 +45,7 @@
3645
"python.terminal.activateEnvironment": true,
3746
"ansible.validation.lint.path": "ansible-lint",
3847
"ansible.ansible.path": "ansible",
39-
"ansible.python.interpreterPath": ".devcontainer/.venv-ansible/bin/python",
48+
"ansible.python.interpreterPath": "python",
4049
"files.associations": {
4150
"*.j2": "ansible-jinja",
4251
"**/defaults/**/*.y*ml": "ansible",
@@ -66,7 +75,6 @@
6675
]
6776
}
6877
},
69-
"onCreateCommand": "bash ./.devcontainer/scripts/on-create-command.sh",
7078
"mounts": [
7179
{
7280
"source": "${localWorkspaceFolder}/.devcontainer/ssh-keys/server",
@@ -78,6 +86,5 @@
7886
"target": "/home/vscode/.history_export",
7987
"type": "volume"
8088
}
81-
],
82-
"postCreateCommand": "bash ./.devcontainer/scripts/post-create-command.sh"
89+
]
8390
}

.devcontainer/docker-compose.base.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
services:
3+
ansible-debian-base:
4+
build:
5+
context: .
6+
dockerfile: ./Dockerfiles/Dockerfile-Debian-12-base
7+
args:
8+
TZ: Europe/Berlin
9+
image: local/debian-12-base
10+
deploy:
11+
replicas: 0

.devcontainer/docker-compose.dev.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
services:
3+
ansible-control:
4+
build:
5+
context: .
6+
dockerfile: ./Dockerfiles/Dockerfile-Debian-12-control
7+
args:
8+
TZ: Europe/Berlin
9+
ANSIBLE_VERSION: ${ANSIBLE_VERSION:-<10.0.0}
10+
ANSIBLE_LINT_VERSION: ${ANSIBLE_LINT_VERSION:->=24.0.0}
11+
image: ansible-control
12+
# container_name: ansible-control
13+
hostname: control.ansible
14+
environment:
15+
- 'TZ=Europe/Berlin'
16+
volumes:
17+
- ..:/workspace/ansible-playground:cached
18+
networks:
19+
- ansible-playground
20+
command: /bin/sh -c "while sleep 1; do :; done"

.devcontainer/docker-compose.yml

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1-
version: '3'
2-
1+
---
32
services:
43
ansible-client-debian:
54
build:
6-
context: ./Dockerfiles
7-
dockerfile: Dockerfile-Debian-12
5+
context: .
6+
dockerfile: ./Dockerfiles/Dockerfile-Debian-12-client
7+
args:
8+
TZ: Europe/Berlin
89
image: ansible-client-debian
9-
container_name: ansible-client-debian
10+
# container_name: ansible-client-debian
1011
hostname: debian.client.ansible
1112
environment:
12-
- 'TZ=Europe/Berlin'
13-
volumes:
14-
- ./ssh-keys/clients/authorized_keys:/root/authorized_keys:ro
13+
- "TZ=Europe/Berlin"
14+
# volumes:
15+
# - ./ssh-keys/clients/authorized_keys:/root/.ssh/authorized_keys:ro
16+
# - ./ssh-keys/clients/PermitRootLogin.conf:/etc/ssh/sshd_config.d/PermitRootLogin.conf
1517
networks:
1618
- ansible-playground
1719

1820
ansible-client-ubuntu:
1921
build:
20-
context: ./Dockerfiles
21-
dockerfile: Dockerfile-Ubuntu-22.04
22+
context: .
23+
dockerfile: ./Dockerfiles/Dockerfile-Ubuntu-2204
24+
args:
25+
TZ: Europe/Berlin
2226
image: ansible-client-ubuntu
23-
container_name: ansible-client-ubuntu
27+
# container_name: ansible-client-ubuntu
2428
hostname: ubuntu.client.ansible
2529
environment:
26-
- 'TZ=Europe/Berlin'
27-
volumes:
28-
- ./ssh-keys/clients/authorized_keys:/root/authorized_keys:ro
30+
- "TZ=Europe/Berlin"
31+
# volumes:
32+
# - ./ssh-keys/clients/authorized_keys:/root/.ssh/authorized_keys:ro
33+
# - ./ssh-keys/clients/PermitRootLogin.conf:/etc/ssh/sshd_config.d/PermitRootLogin.conf
2934
networks:
3035
- ansible-playground
3136

3237
ansible-client-alma:
3338
build:
34-
context: ./Dockerfiles
35-
dockerfile: Dockerfile-Alma-8
39+
context: .
40+
dockerfile: ./Dockerfiles/Dockerfile-Alma-8
41+
args:
42+
TZ: Europe/Berlin
3643
image: ansible-client-alma
37-
container_name: ansible-client-alma
44+
# container_name: ansible-client-alma
3845
hostname: alma.client.ansible
3946
environment:
40-
- 'TZ=Europe/Berlin'
41-
volumes:
42-
- ./ssh-keys/clients/authorized_keys:/root/authorized_keys:ro
47+
- "TZ=Europe/Berlin"
48+
# volumes:
49+
# - ./ssh-keys/clients/authorized_keys:/root/.ssh/authorized_keys:ro
50+
# - ./ssh-keys/clients/PermitRootLogin.conf:/etc/ssh/sshd_config.d/PermitRootLogin.conf
4351
networks:
4452
- ansible-playground
4553

4654
ansible-client-suse:
4755
build:
48-
context: ./Dockerfiles
49-
dockerfile: Dockerfile-OpenSUSE-Leap-15
56+
context: .
57+
dockerfile: ./Dockerfiles/Dockerfile-OpenSUSE-Leap-15
58+
args:
59+
TZ: Europe/Berlin
5060
image: ansible-client-suse
51-
container_name: ansible-client-suse
61+
# container_name: ansible-client-suse
5262
hostname: suse.client.ansible
5363
environment:
54-
- 'TZ=Europe/Berlin'
55-
volumes:
56-
- ./ssh-keys/clients/authorized_keys:/root/authorized_keys:ro
64+
- "TZ=Europe/Berlin"
65+
# volumes:
66+
# - ./ssh-keys/clients/authorized_keys:/root/.ssh/authorized_keys:ro
67+
# - ./ssh-keys/clients/PermitRootLogin.conf:/etc/ssh/sshd_config.d/PermitRootLogin.conf
5768
networks:
5869
- ansible-playground
5970

6071
networks:
6172
ansible-playground:
62-
external: true

.devcontainer/scripts/initialize-command.sh

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22

33
DOCKER_VOLUME_NAME="devcontainer-history"
44

5-
if ! docker volume inspect "${DOCKER_VOLUME_NAME}" >/dev/null 2>&1; then
6-
docker volume create "${DOCKER_VOLUME_NAME}"
5+
if ! docker volume inspect "${DOCKER_VOLUME_NAME}" &>/dev/null 2>&1; then
6+
echo -n "INITIALIZE COMMAND :: Creating Docker volume '${DOCKER_VOLUME_NAME}'... "
7+
if docker volume create "${DOCKER_VOLUME_NAME}" &>/dev/null; then
8+
echo "done"
9+
fi
710
else
811
echo "INITIALIZE COMMAND :: Docker volume '${DOCKER_VOLUME_NAME}' already exists - no need to create."
912
fi
1013

11-
if [[ ! $(docker network ls -qf name=ansible-playground) =~ [0-9a-z]{12} ]]; then
12-
docker network create ansible-playground
13-
fi
14-
build_images=()
15-
while read -r image; do
16-
if ! docker image ls "${image}" | grep -q "${image}"; then
17-
build_images+=("${image}")
18-
fi
19-
done < <(awk '/image:/ {print $NF}' .devcontainer/docker-compose.yml)
20-
if [[ ${#build_images[@]} -gt 0 ]]; then
21-
echo "-------------- BUILDING DOCKER IMAGES --------------"
22-
docker compose -f .devcontainer/docker-compose.yml build "${build_images[@]}"
23-
fi
24-
echo "---------------- DOCKER IMAGES BUILT ---------------"
14+
### Build debian base image
15+
echo "INITIALIZE COMMAND :: Building Debian 12 base image..."
16+
docker compose -f .devcontainer/docker-compose.base.yml build
2517

26-
if [[ ! -f "${PWD}/ssh-keys/clients/authorized_keys" ]]; then
27-
touch "${PWD}/.devcontainer/ssh-keys/clients/authorized_keys"
28-
fi
18+
# if [[ ! $(docker network ls -qf name=ansible-playground) =~ [0-9a-z]{12} ]]; then
19+
# docker network create ansible-playground
20+
# fi
21+
# build_images=()
22+
# while read -r image; do
23+
# if ! docker image ls "${image}" | grep -q "${image}"; then
24+
# build_images+=("${image}")
25+
# fi
26+
# done < <(awk '/image:/ {print $NF}' .devcontainer/docker-compose.yml)
27+
# if [[ ${#build_images[@]} -gt 0 ]]; then
28+
# echo "-------------- BUILDING DOCKER IMAGES --------------"
29+
# docker compose -f .devcontainer/docker-compose.yml build "${build_images[@]}"
30+
# fi
31+
# echo "---------------- DOCKER IMAGES BUILT ---------------"
32+
33+
# if [[ ! -f "${PWD}/ssh-keys/clients/authorized_keys" ]]; then
34+
# touch "${PWD}/.devcontainer/ssh-keys/clients/authorized_keys"
35+
# fi
2936

30-
docker compose -f .devcontainer/docker-compose.yml up -d
37+
# docker compose -f .devcontainer/docker-compose.yml up -d
3138

3239
if ! find .devcontainer/ssh-keys -type f -name id_rsa | grep -q .; then
3340
echo "---------------- DEPLOY SSH KEYFILES ---------------"
@@ -53,11 +60,10 @@ if ! find .devcontainer/ssh-keys -type f -name id_rsa | grep -q .; then
5360
bash -c 'chown -R 1000:1000 /root/.ssh/'
5461
fi
5562

56-
echo "Copy 'authorized_keys' into client's root ssh dir"
57-
for s in $(docker compose -f .devcontainer/docker-compose.yml ps --services --status running); do
58-
echo "${s}"
59-
docker compose -f .devcontainer/docker-compose.yml exec "${s}" mkdir -p /root/.ssh
60-
docker compose -f .devcontainer/docker-compose.yml exec "${s}" chmod 700 /root/.ssh
61-
docker compose -f .devcontainer/docker-compose.yml exec "${s}" cp -v /root/authorized_keys /root/.ssh/authorized_keys
62-
done
63-
echo "--------------- SSH KEYFILES DEPLOYED --------------"
63+
# echo "Copy 'authorized_keys' into client's root ssh dir"
64+
# for s in $(docker compose -f .devcontainer/docker-compose.yml ps --services --status running); do
65+
# echo "${s}"
66+
# docker compose -f .devcontainer/docker-compose.yml exec "${s}" install --directory --mode=0700 --owner=1000 --group=1000 /root/.ssh
67+
# docker compose -f .devcontainer/docker-compose.yml exec "${s}" cp -v /root/authorized_keys /root/.ssh/authorized_keys
68+
# done
69+
# echo "--------------- SSH KEYFILES DEPLOYED --------------"

0 commit comments

Comments
 (0)