From 94dddd9b0d65ce98e741ccb4339b3f51d529b218 Mon Sep 17 00:00:00 2001 From: Aveal Blomqvist Date: Wed, 17 Aug 2022 15:49:35 +0300 Subject: [PATCH] Add .devcontainer for remote containers --- .devcontainer/Dockerfile | 42 ++++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 28 +++++++++++++++++++++ .devcontainer/docker-compose.yml | 28 +++++++++++++++++++++ 3 files changed, 98 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..ad93099 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,42 @@ +# Update the VARIANT arg in docker-compose.yml to pick an Elixir version: 1.9, 1.10, 1.10.4 +ARG VARIANT=latest +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" +ARG COMMON_SCRIPT_SOURCE="https://raw.githubusercontent.com/microsoft/vscode-dev-containers/main/script-library/common-debian.sh" +ARG COMMON_SCRIPT_SHA="dev-mode" + +# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. +RUN apt-get update \ + && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends curl ca-certificates 2>&1 \ + && curl -sSL ${COMMON_SCRIPT_SOURCE} -o /tmp/common-setup.sh \ + && ([ "${COMMON_SCRIPT_SHA}" = "dev-mode" ] || (echo "${COMMON_SCRIPT_SHA} */tmp/common-setup.sh" | sha256sum -c -)) \ + && /bin/bash /tmp/common-setup.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \ + # + # Install dependencies + && apt-get install -y build-essential redis-server \ + # + # Clean up + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* /tmp/common-setup.sh /tmp/node-setup.sh + +RUN su ${USERNAME} -c "mix local.hex --force \ + && mix local.rebar --force" + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update \ +# && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install additional package. +# RUN mix ... \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..25873be --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +// 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.245.0/containers/elixir +{ + "name": "Elixir (Community)", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/home/app/exq", + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "jakebecker.elixir-ls" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [], + + // 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" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..9384ada --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,28 @@ +version: "3.3" +services: + app: + build: + context: .. + dockerfile: ./.devcontainer/Dockerfile + environment: + VARIANT: "latest" + REDIS_HOST: redis_db + REDIS_PORT: 6379 + REDIS_URL: "redis://redis_db:6379" + CACHE_TEST_REDIS_URL: "redis://redis_db:6379/2" + CACHE_DEV_REDIS_URL: "redis://redis_db:6379/3" + # just DEV, because jobs don't use redis in tests + JOBS_DEV_REDIS_URL: "redis://redis_db:6379/4" + command: sleep infinity + volumes: + - ..:/home/app/exq:cached + links: + - redis_db + depends_on: + - redis_db + + redis_db: + image: redis:4 + restart: always + expose: + - "6379"