Skip to content

Commit

Permalink
Merge pull request #16 from theohbrothers/feature/add-docker-variants
Browse files Browse the repository at this point in the history
Feature: Add `docker` variants
  • Loading branch information
leojonathanoh authored Dec 27, 2022
2 parents c967e01 + d58c8a2 commit 7acdeef
Show file tree
Hide file tree
Showing 38 changed files with 1,948 additions and 82 deletions.
1,382 changes: 1,351 additions & 31 deletions .github/workflows/ci-master-pr.yml

Large diffs are not rendered by default.

41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,60 @@ Dockerized [`code-server`](https://github.com/coder/code-server).
| Tag | Dockerfile Build Context |
|:-------:|:---------:|
| `:v4.9.1-alpine-3.15`, `:latest` | [View](variants/v4.9.1-alpine-3.15 ) |
| `:v4.9.1-docker-alpine-3.15` | [View](variants/v4.9.1-docker-alpine-3.15 ) |
| `:v4.9.1-docker-rootless-alpine-3.15` | [View](variants/v4.9.1-docker-rootless-alpine-3.15 ) |
| `:v4.8.3-alpine-3.15` | [View](variants/v4.8.3-alpine-3.15 ) |
| `:v4.8.3-docker-alpine-3.15` | [View](variants/v4.8.3-docker-alpine-3.15 ) |
| `:v4.8.3-docker-rootless-alpine-3.15` | [View](variants/v4.8.3-docker-rootless-alpine-3.15 ) |
| `:v4.8.3-pwsh-7.3.1-alpine-3.15` | [View](variants/v4.8.3-pwsh-7.3.1-alpine-3.15 ) |
| `:v4.8.3-pwsh-7.2.8-alpine-3.15` | [View](variants/v4.8.3-pwsh-7.2.8-alpine-3.15 ) |
| `:v4.8.3-pwsh-7.1.7-alpine-3.15` | [View](variants/v4.8.3-pwsh-7.1.7-alpine-3.15 ) |
| `:v4.8.3-pwsh-7.0.13-alpine-3.15` | [View](variants/v4.8.3-pwsh-7.0.13-alpine-3.15 ) |
| `:v4.7.1-alpine-3.15` | [View](variants/v4.7.1-alpine-3.15 ) |
| `:v4.7.1-docker-alpine-3.15` | [View](variants/v4.7.1-docker-alpine-3.15 ) |
| `:v4.7.1-docker-rootless-alpine-3.15` | [View](variants/v4.7.1-docker-rootless-alpine-3.15 ) |
| `:v4.6.1-alpine-3.15` | [View](variants/v4.6.1-alpine-3.15 ) |
| `:v4.6.1-docker-alpine-3.15` | [View](variants/v4.6.1-docker-alpine-3.15 ) |
| `:v4.6.1-docker-rootless-alpine-3.15` | [View](variants/v4.6.1-docker-rootless-alpine-3.15 ) |

Base variants do not contain additional tools. E.g. `v4.9.1-alpine-3.15`.

Incremental variants contain additional tools. E.g. `v4.8.3-pwsh-7.3.1-alpine-3.15`:
Incremental variants contain additional tools. E.g. `v4.9.1-docker-alpine-3.15`:

- `pwsh`: Powershell
- `docker`: [docker](https://docs.docker.com/engine/)
- `docker-rootless`: [Rootless docker](https://docs.docker.com/engine/security/rootless/)
- `pwsh`: [Powershell](https://github.com/PowerShell/PowerShell)

## Usage

To run a base variant:

```sh
docker run --name code-server --rm -it -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:latest
```

To run an incremental variant:

```sh
# docker or docker-rootless
docker run --name code-server --rm -it --privileged -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:v4.9.1-docker-alpine-3.15

# pwsh
docker run --name code-server --rm -it --privileged -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:
```

`code-server` is now available at http://127.0.0.1:8080. To login, use the password in the config file:

```sh
# code-server available at http://127.0.0.1:8080
docker run --name code-server -it -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:latest
# Login using the password in the config file
docker exec code-server sh -c 'cat ~/.config/code-server/config.yaml'
```

## Notes

- The default user is named `user` with UID `1000`. To escalate as `root`, use `sudo`.
- Users should provision their own configuration files at entrypoint. Examples include dot files such as `~/.bash_aliases`, `~/.gitconfig`, and `code` configs such as `~/.local/share/code-server/User/keybindings.json` and `~/.local/share/code-server/User/settings.json`.
- To ensure `bash-completion` works, ensure `/etc/profile.d/bash_completion.sh` is sourced by `~/.bashrc`. When `exec`ing into the container, use a login shell (E.g. `docker exec -it <container> bash -l`).

## Development

Requires Windows `powershell` or [`pwsh`](https://github.com/PowerShell/PowerShell).
Expand Down
18 changes: 16 additions & 2 deletions generate/definitions/VARIANTS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.15'
subvariants = @(
@{ components = @(); tag_as_latest = $true } # Base
@{ components = @( 'docker' ) } # Incremental
@{ components = @( 'docker-rootless' ) } # Incremental
)
}
@{
Expand All @@ -16,6 +18,8 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.15'
subvariants = @(
@{ components = @() } # Base
@{ components = @( 'docker' ) } # Incremental
@{ components = @( 'docker-rootless' ) } # Incremental
@{ components = @( 'pwsh-7.3.1' ) } # Incremental
@{ components = @( 'pwsh-7.2.8' ) } # Incremental
@{ components = @( 'pwsh-7.1.7' ) } # Incremental
Expand All @@ -29,6 +33,8 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.15'
subvariants = @(
@{ components = @() } # Base
@{ components = @( 'docker' ) } # Incremental
@{ components = @( 'docker-rootless' ) } # Incremental
)
}
@{
Expand All @@ -38,6 +44,8 @@ $local:VARIANTS_MATRIX = @(
distro_version = '3.15'
subvariants = @(
@{ components = @() } # Base
@{ components = @( 'docker' ) } # Incremental
@{ components = @( 'docker-rootless' ) } # Incremental
)
}
# @{
Expand Down Expand Up @@ -99,8 +107,14 @@ $VARIANTS_SHARED = @{
templates = @{
'Dockerfile' = @{
common = $true
includeHeader = $false
includeFooter = $false
passes = @(
@{
variables = @{}
}
)
}
'docker-entrypoint.sh' = @{
common = $true
passes = @(
@{
variables = @{}
Expand Down
70 changes: 57 additions & 13 deletions generate/templates/Dockerfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,64 @@ RUN code-server --install-extension vscode-icons-team.vscode-icons@11.13.0
RUN code-server --install-extension redhat.vscode-xml@0.18.0
# yaml
RUN code-server --install-extension redhat.vscode-yaml@1.9.1
# Remove the default config file created when extensions are installed
RUN rm -v ~/.config/code-server/config.yaml
ENV LANG=en_US.UTF-8
USER user
WORKDIR /home/user
CMD [ "code-server", "--bind-addr", "0.0.0.0:8080", "--disable-telemetry", "--disable-update-check" ]
"@
}else {
# Incremental build
@'
ARG BASE_IMAGE
FROM $BASE_IMAGE
'@
foreach ($c in $VARIANT['_metadata']['components']) {
if ($c -eq 'docker') {
@'
USER root
# Install docker
RUN apk add --no-cache shadow-uidmap fuse-overlayfs iproute2 iptables ip6tables
RUN apk add --no-cache docker
RUN adduser user docker
# Install docker compose v2
RUN apk add --no-cache docker-cli-compose
# Install docker-compose v1 (deprecated, but for backward compatibility)
RUN apk add --no-cache docker-compose
'@
foreach ($c in $VARIANT['_metadata']['components']) {

}
if ($c -eq 'docker-rootless') {
@'
USER root
# Install rootless docker
# See: https://docs.docker.com/engine/security/rootless/
RUN apk add --no-cache shadow-uidmap fuse-overlayfs iproute2 iptables ip6tables
RUN apk add --no-cache bash-completion
RUN echo user:100000:65536 >/etc/subuid
RUN echo user:100000:65536 >/etc/subgid
USER user
RUN wget -qO- https://get.docker.com/rootless | sh
ENV XDG_RUNTIME_DIR=/home/user/.docker/run
ENV PATH=/home/user/bin:$PATH
ENV DOCKER_HOST=unix:///home/user/.docker/run/docker.sock
USER root
# Install docker compose v2
RUN apk add --no-cache docker-cli-compose
# Install docker-compose v1 (deprecated, but for backward compatibility)
RUN apk add --no-cache docker-compose
'@
}
if ($c -match 'pwsh-([^-]+)') {
$v = $matches[1]
@"
USER root
# Install pwsh
# See: https://learn.microsoft.com/en-us/powershell/scripting/install/install-alpine?view=powershell-7.3
RUN apk add --no-cache \
Expand Down Expand Up @@ -120,16 +156,24 @@ RUN pwsh -c 'Install-Module Pester -Force -Scope AllUsers -MinimumVersion 4.0.0
# Install extensions
USER user
RUN code-server --install-extension ms-vscode.powershell@2021.12.0
"@
}
}
}

@"
# Remove the default config file created when extensions are installed
RUN rm -v ~/.config/code-server/config.yaml
# Restore user
# Remove the default code-server config file created when extensions are installed
USER user
RUN rm -fv ~/.config/code-server/config.yaml
USER root
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
ENV LANG=en_US.UTF-8
USER user
WORKDIR /home/user
CMD [ "/docker-entrypoint.sh" ]
"@
}
41 changes: 34 additions & 7 deletions generate/templates/README.md.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,46 @@ Base variants do not contain additional tools. E.g. ``$( $VARIANTS | ? { $_['tag
Incremental variants contain additional tools. E.g. ``$( $VARIANTS | ? { $_['_metadata']['base_tag'] } | Select-Object -First 1 | Select-Object -ExpandProperty tag )``:
- ``pwsh``: Powershell
- ``docker``: [docker](https://docs.docker.com/engine/)
- ``docker-rootless``: [Rootless docker](https://docs.docker.com/engine/security/rootless/)
- ``pwsh``: [Powershell](https://github.com/PowerShell/PowerShell)
"@
@'
@"
## Usage
```sh
# code-server available at http://127.0.0.1:8080
docker run --name code-server -it -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:latest
# Login using the password in the config file
To run a base variant:
``````sh
docker run --name code-server --rm -it -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:latest
``````
To run an incremental variant:
``````sh
# docker or docker-rootless
docker run --name code-server --rm -it --privileged -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:$( $VARIANTS | ? { $_['_metadata']['components'] -contains 'docker' } | Select-Object -First 1 | Select-Object -ExpandProperty tag )
# pwsh
docker run --name code-server --rm -it --privileged -p 127.0.0.1:8080:8080 theohbrothers/docker-code-server:$( $VARIANTS | ? { $_['_metadata']['components'] -contains 'pwsh' } | Select-Object -First 1 | Select-Object -ExpandProperty tag )
``````
``code-server`` is now available at http://127.0.0.1:8080. To login, use the password in the config file:
``````sh
docker exec code-server sh -c 'cat ~/.config/code-server/config.yaml'
```
``````
"@

@'
## Notes
- The default user is named `user` with UID `1000`. To escalate as `root`, use `sudo`.
- Users should provision their own configuration files at entrypoint. Examples include dot files such as `~/.bash_aliases`, `~/.gitconfig`, and `code` configs such as `~/.local/share/code-server/User/keybindings.json` and `~/.local/share/code-server/User/settings.json`.
- To ensure `bash-completion` works, ensure `/etc/profile.d/bash_completion.sh` is sourced by `~/.bashrc`. When `exec`ing into the container, use a login shell (E.g. `docker exec -it <container> bash -l`).
## Development
Expand Down
30 changes: 30 additions & 0 deletions generate/templates/docker-entrypoint.sh.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@'
#!/bin/sh
set -eu
'@

if ($VARIANT['_metadata']['base_tag']) {
# Incremental build
foreach ($c in $VARIANT['_metadata']['components']) {
if ($c -eq 'docker') {
@'
echo "Starting dockerd"
sudo dockerd &
'@
}
if ($c -eq 'docker-rootless') {
@'
echo "Starting rootless dockerd"
PATH=/home/user/bin:/sbin:/usr/sbin:$PATH dockerd-rootless.sh &
'@
}
}
}

@'
echo "Starting code-server"
exec code-server --bind-addr 0.0.0.0:8080 --disable-telemetry --disable-update-check
'@
12 changes: 9 additions & 3 deletions variants/v4.6.1-alpine-3.15/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ RUN code-server --install-extension vscode-icons-team.vscode-icons@11.13.0
RUN code-server --install-extension redhat.vscode-xml@0.18.0
# yaml
RUN code-server --install-extension redhat.vscode-yaml@1.9.1
# Remove the default config file created when extensions are installed
RUN rm -v ~/.config/code-server/config.yaml

# Remove the default code-server config file created when extensions are installed
USER user
RUN rm -fv ~/.config/code-server/config.yaml

USER root
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

ENV LANG=en_US.UTF-8
USER user
WORKDIR /home/user
CMD [ "code-server", "--bind-addr", "0.0.0.0:8080", "--disable-telemetry", "--disable-update-check" ]
CMD [ "/docker-entrypoint.sh" ]
4 changes: 4 additions & 0 deletions variants/v4.6.1-alpine-3.15/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -eu
echo "Starting code-server"
exec code-server --bind-addr 0.0.0.0:8080 --disable-telemetry --disable-update-check
29 changes: 29 additions & 0 deletions variants/v4.6.1-docker-alpine-3.15/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG BASE_IMAGE
FROM $BASE_IMAGE

USER root

# Install docker
RUN apk add --no-cache shadow-uidmap fuse-overlayfs iproute2 iptables ip6tables
RUN apk add --no-cache docker
RUN adduser user docker

# Install docker compose v2
RUN apk add --no-cache docker-cli-compose

# Install docker-compose v1 (deprecated, but for backward compatibility)
RUN apk add --no-cache docker-compose


# Remove the default code-server config file created when extensions are installed
USER user
RUN rm -fv ~/.config/code-server/config.yaml

USER root
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

ENV LANG=en_US.UTF-8
USER user
WORKDIR /home/user
CMD [ "/docker-entrypoint.sh" ]
6 changes: 6 additions & 0 deletions variants/v4.6.1-docker-alpine-3.15/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -eu
echo "Starting dockerd"
sudo dockerd &
echo "Starting code-server"
exec code-server --bind-addr 0.0.0.0:8080 --disable-telemetry --disable-update-check
Loading

0 comments on commit 7acdeef

Please sign in to comment.