-
Notifications
You must be signed in to change notification settings - Fork 43
chore: update dind examples to use onCreateCommand #350
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4581fa
chore: update dind examples
johnstcn 482a212
fix group membership
johnstcn cd83f04
update rootless example
johnstcn e7139d9
address code review comments
johnstcn e9a45f9
03_dind_feature: apply workaround for /var/run
johnstcn df95d7d
fixup! 03_dind_feature: apply workaround for /var/run
johnstcn c11e0e3
fixup! fixup! 03_dind_feature: apply workaround for /var/run
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
FROM ubuntu:noble | ||
|
||
# Install Docker using Docker's convenience script. | ||
RUN apt-get update && \ | ||
apt-get install -y curl apt-transport-https && \ | ||
curl -fsSL https://get.docker.com/ | sh -s - | ||
ADD entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
apt-get install -y curl sudo apt-transport-https && \ | ||
curl -fsSL https://get.docker.com/ | sh -s - | ||
|
||
# The ubuntu:noble image includes a non-root user by default, | ||
# but it does not have sudo privileges. We need to set this up. | ||
# Note: we chown /var/run/docker.sock to the non-root user | ||
# in the onCreateCommand script. Ideally you would add the | ||
# non-root user to the docker group, but in this scenario | ||
# this is a 'single-user' environment. It also avoids us | ||
# having to run `newgrp docker`. | ||
RUN echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu | ||
|
||
# Add our onCreateCommand script. | ||
ADD on-create.sh /on-create.sh | ||
|
||
# Switch to the non-root user. | ||
USER ubuntu | ||
|
||
ENTRYPOINT ["bash"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
} | ||
} | ||
}, | ||
"onCreateCommand": "/on-create.sh" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Start Docker in the background. | ||
sudo -u root /bin/sh -c 'nohup dockerd > /var/log/docker.log &' | ||
|
||
# Wait up to 10 seconds for Docker to start. | ||
for attempt in $(seq 1 10); do | ||
if [[ $attempt -eq 10 ]]; then | ||
echo "Failed to start Docker" | ||
exit 1 | ||
fi | ||
if [[ ! -e /var/run/docker.sock ]]; then | ||
sleep 1 | ||
else | ||
break | ||
fi | ||
done | ||
|
||
# Change the owner of the Docker socket so that the non-root user can use it. | ||
sudo chown ubuntu:docker /var/run/docker.sock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
FROM ubuntu:noble | ||
ADD entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
|
||
# Install some dependencies such as curl and sudo. | ||
# Also set up passwordless sudo for the ubuntu user. | ||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
curl \ | ||
sudo \ | ||
apt-transport-https && \ | ||
echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu | ||
|
||
# Add our onCreateCommand script. | ||
ADD on-create.sh /on-create.sh | ||
|
||
# Switch to the non-root user. | ||
USER ubuntu | ||
|
||
# The devcontainer feature provides /usr/local/share/docker-init.sh | ||
# which will handle most of the steps of setting up Docker. | ||
# We can't put this in the entrypoint as it gets overridden, so | ||
# we call it in the on-create script. | ||
ENTRYPOINT ["bash"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Known issue: Kaniko does not symlink /run => /var/run properly. | ||
# This results in /var/run/ being owned by root:root which interferes | ||
# with accessing the Docker socket even if the permissions are set | ||
# correctly. Workaround: symlink it manually | ||
sudo ln -s /run /var/run | ||
|
||
# Run the docker init script. This needs to be | ||
# run as root. It will take care of starting the | ||
# daemon and adding the ubuntu user to the docker | ||
# group. | ||
sudo /usr/local/share/docker-init.sh | ||
|
||
# Change the owner of the Docker socket so that the non-root user can use it. | ||
sudo chown ubuntu:docker /var/run/docker.sock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
} | ||
} | ||
}, | ||
"onCreateCommand": "/on-create.sh" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not support setting entrypoint in the Dockerfile at all? Maybe we should in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My observation is that whatever entrypoint you set gets overridden by
ENVBUILDER_INIT_COMMAND
/ENVBUILDER_INIT_SCRIPT
. But agreed, we should fall back to the entrypoint in the Dockerfile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a Coder workspace we need to have
coder_agent.*.init_script
as the entry point so another option to handle theENTRYPOINT
is to run it as part ofcoder_agent
startup_script
. This will work for at least the case when envbuilder is used with Coder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #351 to follow up on this.