Skip to content

Commit

Permalink
feat: setup docker in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Aug 19, 2024
1 parent 3c6a34b commit c084309
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 33 deletions.
Empty file added .github/workflows/ci.yml
Empty file.
12 changes: 11 additions & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

WORKDIR /home/${USER}
Expand All @@ -57,4 +63,8 @@ RUN if [ -n "$PACKAGES" ]; then \
pkgx install ${PACKAGES};\
fi

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]
5 changes: 5 additions & 0 deletions build/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
1 change: 1 addition & 0 deletions build/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "docker_image" "pkgx" {
resource "docker_container" "pkgx" {
image = docker_image.pkgx.image_id
name = "pkgx-workspace"
privileged = true

volumes {
volume_name = "pkgx-workspace"
Expand Down
13 changes: 12 additions & 1 deletion devbox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

RUN curl --proto =https --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux --extra-conf "sandbox = false" --init none --no-confirm
Expand Down Expand Up @@ -58,4 +64,9 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash

ENV BASH_ENV=/home/${USER}/.bashrc

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]

5 changes: 5 additions & 0 deletions devbox/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
11 changes: 6 additions & 5 deletions devbox/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
Expand All @@ -17,8 +17,9 @@ resource "docker_image" "devbox" {
}

resource "docker_container" "devbox" {
image = docker_image.devbox.image_id
name = "devbox-workspace"
image = docker_image.devbox.image_id
name = "devbox-workspace"
privileged = true

volumes {
volume_name = "devbox-workspace"
Expand All @@ -27,8 +28,8 @@ resource "docker_container" "devbox" {
}

volumes {
volume_name = "devbox-nix"
volume_name = "devbox-nix"
container_path = "/nix"
read_only = false
read_only = false
}
}
13 changes: 12 additions & 1 deletion devenv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

RUN sudo chown -R ${USER}:${USER} /nix/store /nix/var
Expand Down Expand Up @@ -63,4 +69,9 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash

ENV BASH_ENV=/home/${USER}/.bashrc

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]

5 changes: 5 additions & 0 deletions devenv/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
11 changes: 6 additions & 5 deletions devenv/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
Expand All @@ -17,8 +17,9 @@ resource "docker_image" "devenv" {
}

resource "docker_container" "devenv" {
image = docker_image.devenv.image_id
name = "devenv-workspace"
image = docker_image.devenv.image_id
name = "devenv-workspace"
privileged = true

volumes {
volume_name = "devenv-workspace"
Expand All @@ -27,8 +28,8 @@ resource "docker_container" "devenv" {
}

volumes {
volume_name = "devenv-nix"
volume_name = "devenv-nix"
container_path = "/nix"
read_only = false
read_only = false
}
}
13 changes: 12 additions & 1 deletion flox/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

ENV PATH=${PATH}:/home/${USER}/.nix-profile/bin
Expand Down Expand Up @@ -58,4 +64,9 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash

ENV BASH_ENV=/home/${USER}/.bashrc

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]

5 changes: 5 additions & 0 deletions flox/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
1 change: 1 addition & 0 deletions flox/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "docker_image" "flox" {
resource "docker_container" "flox" {
image = docker_image.flox.image_id
name = "flox-workspace"
privileged = true

volumes {
volume_name = "flox-workspace"
Expand Down
13 changes: 12 additions & 1 deletion homebrew/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

SHELL ["bash", "-c"]
Expand All @@ -54,4 +60,9 @@ RUN if [ -n "$PACKAGES" ]; then \
brew install ${PACKAGES}; exit 0;\
fi

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]

5 changes: 5 additions & 0 deletions homebrew/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
7 changes: 4 additions & 3 deletions homebrew/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
Expand All @@ -17,8 +17,9 @@ resource "docker_image" "brew" {
}

resource "docker_container" "brew" {
image = docker_image.brew.image_id
name = "brew-workspace"
image = docker_image.brew.image_id
name = "brew-workspace"
privileged = true

volumes {
volume_name = "brew-workspace"
Expand Down
19 changes: 10 additions & 9 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
Expand All @@ -10,28 +10,29 @@ terraform {
provider "docker" {}

resource "docker_image" "default" {
name = var.image
count = var.context != null ? 0 : 1
name = var.image
count = var.context != null ? 0 : 1
}

resource "docker_image" "base" {
name = var.workspace_name
name = var.workspace_name
count = var.context != null ? 1 : 0

build {
context = var.context
build_args = {
USER = var.user
USER = var.user
PACKAGES = join(" ", var.packages)
}
}
}

resource "docker_container" "base" {
image = var.context != null ? docker_image.base[0].image_id : docker_image.default[0].image_id
name = var.workspace_name
hostname = var.hostname

image = var.context != null ? docker_image.base[0].image_id : docker_image.default[0].image_id
name = var.workspace_name
hostname = var.hostname
privileged = true

dynamic "volumes" {
for_each = var.volumes
content {
Expand Down
13 changes: 12 additions & 1 deletion nix/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

RUN sudo chown -R ${USER}:${USER} /nix/store/.links /nix/var
Expand All @@ -51,4 +57,9 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://setup.atuin.sh | bash

ENV BASH_ENV=/home/${USER}/.bashrc

ENTRYPOINT [ "code", "-v", "tunnel" ]
COPY entry.sh /usr/local/bin/entry.sh

RUN sudo chmod a+x /usr/local/bin/entry.sh

ENTRYPOINT [ "entry.sh" ]

5 changes: 5 additions & 0 deletions nix/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
11 changes: 6 additions & 5 deletions nix/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
Expand All @@ -17,8 +17,9 @@ resource "docker_image" "nix" {
}

resource "docker_container" "nix" {
image = docker_image.nix.image_id
name = "nix-workspace"
image = docker_image.nix.image_id
name = "nix-workspace"
privileged = true

volumes {
volume_name = "nix-workspace"
Expand All @@ -27,8 +28,8 @@ resource "docker_container" "nix" {
}

volumes {
volume_name = "nix-store"
volume_name = "nix-store"
container_path = "/nix"
read_only = false
read_only = false
}
}
6 changes: 6 additions & 0 deletions pkgx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ RUN addgroup --gid $GROUP_ID ${USER} \

RUN mkdir -p /home/${USER} && chown -R ${USER}:${USER} /home/${USER}

ENV DOCKER_TLS_CERTDIR=/certs
RUN mkdir /certs /certs/client && chmod 1777 /certs /certs/client
COPY --from=docker:27-dind /usr/local/bin/ /usr/local/bin/
COPY --from=docker:27-dind /usr/local/libexec/ /usr/local/libexec/
VOLUME /var/lib/docker

USER ${USER}

WORKDIR /home/${USER}
Expand Down
5 changes: 5 additions & 0 deletions pkgx/entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/bash

sudo dockerd-entrypoint.sh >/dev/null 2>/dev/null &

code -v tunnel
1 change: 1 addition & 0 deletions pkgx/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resource "docker_image" "pkgx" {
resource "docker_container" "pkgx" {
image = docker_image.pkgx.image_id
name = "pkgx-workspace"
privileged = true

volumes {
volume_name = "pkgx-workspace"
Expand Down

0 comments on commit c084309

Please sign in to comment.