From 078461ac70d03c7787362bb8d5e13841d8bb229e Mon Sep 17 00:00:00 2001 From: Kevin Avignon <6740474+Kavignon@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:21:11 -0500 Subject: [PATCH 1/5] Add Zsh setup to devcontainer with plugins and default shell. - Installed Zsh and set it as the default shell using CMD. - Added Antibody for plugin management and configured Zsh with autosuggestions and syntax highlighting. - Set up `.zshrc` with a default theme, aliases, and plugin sourcing. - Ensured compatibility with Alpine Linux by removing unsupported `chsh` command. - Configured default commands to launch Zsh in the container. --- .devcontainer/Dockerfile | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5b5c540..be1e857 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -14,19 +14,27 @@ RUN mix do local.hex --force, local.rebar --force \ inotify-tools \ bash \ openssh \ - postgresql-client - -# Install GitHub CLI (gh) -RUN apk add --no-cache github-cli - -# Ensure .ssh directory exists -RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh + postgresql-client \ + zsh \ + zsh-autosuggestions \ + zsh-syntax-highlighting \ + zsh-completions \ + && curl -sfL git.io/antibody | sh -s - -b /usr/local/bin + +# Configure Zsh +RUN echo "export ZSH_THEME=\"robbyrussell\"" > /root/.zshrc \ + && echo "alias ll='ls -la'" >> /root/.zshrc \ + && echo "source /usr/share/zsh/plugins/zsh-completions/zsh-completions.plugin.zsh" >> /root/.zshrc \ + && echo "export SHELL=\"/bin/zsh\"" >> /root/.zshrc \ + && antibody bundle zsh-users/zsh-autosuggestions > /root/.zsh_plugins.sh \ + && antibody bundle zsh-users/zsh-syntax-highlighting >> /root/.zsh_plugins.sh \ + && echo "source /root/.zsh_plugins.sh" >> /root/.zshrc # Set up the application directory WORKDIR /workspace # Copy mix files and install dependencies -COPY mix.exs mix.lock ./ +COPY ../mix.exs ../mix.lock /workspace/ RUN mix deps.get --only $MIX_ENV # Copy the rest of the application code @@ -38,5 +46,5 @@ RUN chown -R root:root /workspace # Run compilation in development mode RUN mix compile -# Default command for better interactive experience -CMD ["/bin/bash"] +# Launch Zsh as the default shell +CMD ["/bin/zsh"] From 3aa694409e090a8e8effeb13855bc894023296c3 Mon Sep 17 00:00:00 2001 From: Kevin Avignon <6740474+Kavignon@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:53:38 -0500 Subject: [PATCH 2/5] Fixed location of post_start.sh to run after mount. --- .devcontainer/.devcontainer.json | 32 ------------- .devcontainer/devcontainer.json | 45 ++++++++++++------- .../scripts}/post_start.sh | 0 3 files changed, 30 insertions(+), 47 deletions(-) delete mode 100644 .devcontainer/.devcontainer.json rename {scripts => .devcontainer/scripts}/post_start.sh (100%) diff --git a/.devcontainer/.devcontainer.json b/.devcontainer/.devcontainer.json deleted file mode 100644 index 522c7a6..0000000 --- a/.devcontainer/.devcontainer.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "Elixir Kickoff Development Container", - "image": "ghcr.io/elixir-journey/elixir-kickoff:latest", - "remoteEnv": { - "MIX_ENV": "dev" - }, - "customizations": { - "vscode": { - "extensions": [ - "jakebecker.elixir-ls", - "ms-azuretools.vscode-docker", - "editorconfig.editorconfig", - "eamodio.gitlens", - "streetsidesoftware.code-spell-checker", - "esbenp.prettier-vscode", - "pkief.material-icon-theme" - ], - "settings": { - "terminal.integrated.shell.linux": "/bin/bash" - } - } - }, - "postCreateCommand": "mix deps.get", - "postStartCommand": "../scripts/post_start.sh", - "remoteUser": "vscode", - "mounts": [ - "source=${localWorkspaceFolder},target=/workspace,type=bind", - "source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached", - "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached" - ], - "workspaceFolder": "/workspace" -} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f098348..b60cf6f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,31 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile { - "name": "Existing Dockerfile", - "image": "ghcr.io/elixir-journey/elixir-kickoff:latest" - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Uncomment the next line to run commands after the container is created. - // "postCreateCommand": "cat /etc/os-release", - // Configure tool-specific properties. - // "customizations": {}, - // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "devcontainer" -} \ No newline at end of file + "name": "Elixir Kickoff Development Container", + "image": "ghcr.io/elixir-journey/elixir-kickoff:latest", + "remoteEnv": { + "MIX_ENV": "dev" + }, + "customizations": { + "vscode": { + "extensions": [ + "jakebecker.elixir-ls", + "ms-azuretools.vscode-docker", + "editorconfig.editorconfig", + "eamodio.gitlens", + "streetsidesoftware.code-spell-checker", + "esbenp.prettier-vscode", + "pkief.material-icon-theme" + ], + "settings": { + "terminal.integrated.shell.linux": "/bin/bash" + } + } + }, + "postCreateCommand": "mix deps.get", + "postStartCommand": "/bin/sh /workspace/.devcontainer/scripts/post_start.sh", + "mounts": [ + "source=${localWorkspaceFolder},target=/workspace,type=bind", + "source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached", + "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached" + ], + "workspaceFolder": "/workspace" +} diff --git a/scripts/post_start.sh b/.devcontainer/scripts/post_start.sh similarity index 100% rename from scripts/post_start.sh rename to .devcontainer/scripts/post_start.sh From 8d66082738a7ece90d802834a147f395f07ee4ff Mon Sep 17 00:00:00 2001 From: Kevin Avignon <6740474+Kavignon@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:39:24 -0500 Subject: [PATCH 3/5] Added git ignore to avoid mounting specific files/folder in container. --- .dockerignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..34d06ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# Elixir build files +/_build +/deps + +# Node.js build files (if applicable) +node_modules + +# Editor and OS files +*.swp +*.swo +*.log +.DS_Store + +# Git ignored files +.git From 16e8d46c415fbfc63e21b8e14bb11d25a6674f5e Mon Sep 17 00:00:00 2001 From: Kevin Avignon <6740474+Kavignon@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:41:50 -0500 Subject: [PATCH 4/5] Building the image in multi-stage to reduce size. --- .devcontainer/Dockerfile | 65 ++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index be1e857..8e0c1ea 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,50 +1,43 @@ -# Use an official Elixir image as the base +# Builder stage +FROM elixir:1.17-alpine AS builder + +ENV MIX_ENV=prod + +RUN mix do local.hex --force, local.rebar --force \ + && apk add --no-cache git curl bash openssh postgresql-client + +WORKDIR /app + +COPY mix.exs mix.lock ./ +RUN mix deps.get + +COPY . . +# Ensure directories exist +RUN mkdir -p /app/config /app/rel \ + && mix compile + +# Final stage FROM elixir:1.17-alpine -# Set default environment to development ENV MIX_ENV=dev -# Install Hex, Rebar, and essential tools -RUN mix do local.hex --force, local.rebar --force \ - && apk add --no-cache \ - git \ - nodejs \ - npm \ - curl \ - inotify-tools \ - bash \ - openssh \ - postgresql-client \ - zsh \ - zsh-autosuggestions \ - zsh-syntax-highlighting \ - zsh-completions \ +RUN apk add --no-cache \ + bash openssh postgresql-client \ + git curl zsh zsh-autosuggestions zsh-syntax-highlighting zsh-completions \ && curl -sfL git.io/antibody | sh -s - -b /usr/local/bin +WORKDIR /app + +# Copy the entire project directory +COPY . /app + # Configure Zsh RUN echo "export ZSH_THEME=\"robbyrussell\"" > /root/.zshrc \ && echo "alias ll='ls -la'" >> /root/.zshrc \ - && echo "source /usr/share/zsh/plugins/zsh-completions/zsh-completions.plugin.zsh" >> /root/.zshrc \ && echo "export SHELL=\"/bin/zsh\"" >> /root/.zshrc \ + && echo "source /root/.zsh_plugins.sh" >> /root/.zshrc \ && antibody bundle zsh-users/zsh-autosuggestions > /root/.zsh_plugins.sh \ && antibody bundle zsh-users/zsh-syntax-highlighting >> /root/.zsh_plugins.sh \ - && echo "source /root/.zsh_plugins.sh" >> /root/.zshrc - -# Set up the application directory -WORKDIR /workspace - -# Copy mix files and install dependencies -COPY ../mix.exs ../mix.lock /workspace/ -RUN mix deps.get --only $MIX_ENV - -# Copy the rest of the application code -COPY . . - -# Ensure proper permissions for the workspace directory -RUN chown -R root:root /workspace - -# Run compilation in development mode -RUN mix compile + && antibody bundle romkatv/powerlevel10k >> /root/.zsh_plugins.sh -# Launch Zsh as the default shell CMD ["/bin/zsh"] From c8289e3a31c0b5e5d31399ee18db117c7cd69377 Mon Sep 17 00:00:00 2001 From: Kevin Avignon <6740474+Kavignon@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:55:02 -0500 Subject: [PATCH 5/5] Setting Powerlevel10k in container. --- .devcontainer/Dockerfile | 7 +++++-- .devcontainer/devcontainer.json | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8e0c1ea..c546db5 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,8 +13,7 @@ RUN mix deps.get COPY . . # Ensure directories exist -RUN mkdir -p /app/config /app/rel \ - && mix compile +RUN mkdir -p /app/config /app/rel && mix compile # Final stage FROM elixir:1.17-alpine @@ -31,6 +30,10 @@ WORKDIR /app # Copy the entire project directory COPY . /app +# Default Powerlevel10k configuration +RUN echo "POWERLEVEL9K_MODE=nerdfont-complete" > /root/.p10k.zsh \ + && echo '[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh' >> /root/.zshrc + # Configure Zsh RUN echo "export ZSH_THEME=\"robbyrussell\"" > /root/.zshrc \ && echo "alias ll='ls -la'" >> /root/.zshrc \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b60cf6f..9c74bd8 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -25,7 +25,8 @@ "mounts": [ "source=${localWorkspaceFolder},target=/workspace,type=bind", "source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached", - "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached" + "source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached", + "source=${localEnv:HOME}/.p10k.zsh,target=/root/.p10k.zsh,type=bind,consistency=cached" ], "workspaceFolder": "/workspace" }