Skip to content

Commit

Permalink
Wait for Docker daemon to start, fix docker compose startup script
Browse files Browse the repository at this point in the history
  • Loading branch information
auguwu committed May 2, 2023
1 parent 2da8608 commit 87178d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
3 changes: 2 additions & 1 deletion images/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

FROM ghcr.io/auguwu/coder-images/base
# use April 26th image (since Adoptium doesn't support Ubuntu Lunar yet)
FROM ghcr.io/auguwu/coder-images/base:2023.04.26

ENV USERNAME=noel

Expand Down
29 changes: 18 additions & 11 deletions template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,24 @@ resource "coder_agent" "main" {
# Run Docker in the background
if command -v dockerd &> /dev/null; then
sudo dockerd &
sudo dockerd > /dev/null 2>&1 &
fi
# Wait for Docker to start
while true; do
if curl -s --unix-socket /var/run/docker.sock http/_ping 2>&1 >/dev/null; then
echo "Docker Daemon has started!"
break
fi
echo "Waiting for Docker daemon to start..."
sleep 1
done
# Install code-server if enabled
${var.install_codeserver == true ? "curl -fsSL https://code-server.dev/install.sh | sh" : ""}
${var.install_codeserver == true ? "code-server --auth none --port 3621" : ""}
# I don't know why this happens but, the base Rust image loses all information, so we
# will re-run the rustup-init script, which is still present.
if [ -x /tmp/rustup-init ]; then
/tmp/rustup-init -y --no-modify-path --profile minimal --default-toolchain nightly --default-host=x86_64-unknown-linux-gnu
source $HOME/.cargo/env
rustup component add clippy rustfmt
fi
# Clone the given repository if needed
if ! [ -d "${var.workspace_dir}" ]; then
${var.git_repository != "" ? "git clone ${var.git_repository} ${var.workspace_dir}" : ""}
Expand All @@ -121,6 +123,10 @@ resource "coder_agent" "main" {
mkdir ${var.workspace_dir}
fi
if [ -n "${var.docker_network_name}" ]; then
docker network create "${var.docker_network_name}" --driver=bridge
fi
# if ${var.workspace_dir}/.coder exists, then we will run the pre-init scripts
# and then the Docker Compose project (if any).
if [ -d "${var.workspace_dir}/.coder" ]; then
Expand All @@ -144,7 +150,8 @@ resource "coder_agent" "main" {
dc="docker compose"
fi
if [ -z "$dc" ]; then
if [ -n "$dc" ]; then
echo "[coder::docker-compose] Using \`$dc\` as the Docker compose command!"
$dc -f "${var.workspace_dir}/.coder/docker-compose.yml" up -d
fi
fi
Expand Down
6 changes: 6 additions & 0 deletions template/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ variable "dotfiles_repo" {
default = ""
type = string
}

variable "docker_network_name" {
description = "Name of the Docker network to use."
default = "fluff"
type = string
}

0 comments on commit 87178d5

Please sign in to comment.