From e8e8316f4e48128ab78ad1d724e3b41921b72f4a Mon Sep 17 00:00:00 2001 From: Jessica Phoenix Canady Date: Fri, 12 Apr 2024 14:42:19 -0400 Subject: [PATCH] Add a devcontainer config, maybe? Prob garbage. --- .devcontainer/Dockerfile | 41 ++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 25 +++++++++++++++++++ .devcontainer/docker-compose.yml | 35 +++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..7d119f8 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,41 @@ +# Update the VARIANT arg in docker-compose.yml to pick an Elixir version: 1.9, 1.10, 1.10.4 +ARG VARIANT="1.17.2" +FROM elixir:${VARIANT} + +# This Dockerfile adds a non-root user with sudo access. Update the “remoteUser” property in +# devcontainer.json to use it. More info: https://aka.ms/vscode-remote/containers/non-root-user. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Options for common package install script +ARG INSTALL_ZSH="true" +ARG UPGRADE_PACKAGES="true" + +# Optional Settings for Phoenix +ARG PHOENIX_VERSION="1.7.12" + +# [Optional] Setup nodejs +ARG NODE_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/node-debian.sh" +ARG NODE_SCRIPT_SHA="dev-mode" +ARG NODE_VERSION="none" +ENV NVM_DIR=/usr/local/share/nvm +ENV NVM_SYMLINK_CURRENT=true +ENV PATH=${NVM_DIR}/current/bin:${PATH} + +# [Optional, Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="21.7.3" + +# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. + +RUN su ${USERNAME} -c "mix local.hex --force \ + && mix local.rebar --force \ + && mix archive.install --force hex phx_new ${PHOENIX_VERSION}" + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update \ + && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends postgresql-client inotify-tools + +# [Optional] Uncomment this line to install additional package. +# RUN mix ... diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f4b5e6c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,25 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.5/containers/elixir-phoenix-postgres +{ + "name": "Elixir/Phoenix", + "dockerComposeFile": "docker-compose.yml", + "service": "elixir", + "workspaceFolder": "/workspace", + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or with the host. + "forwardPorts": [4000, 4001, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "mix deps.get" + + // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..1b4ecc9 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,35 @@ +version: "3.8" + +services: + elixir: + build: + context: . + dockerfile: Dockerfile + args: + # Elixir Version: 1.9, 1.10, 1.10.4, ... + VARIANT: "1.16.2" + # Phoenix Version: 1.4.17, 1.5.4, ... + PHOENIX_VERSION: "1.7.12" + # Node Version: 12, 14, ... + NODE_VERSION: "21.7.3" + + volumes: + - ..:/workspace:cached + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: todo_dev + +volumes: + postgres-data: