From: Erik Guzman <erik.guzman@guzman.codes>
Date: Thu, 3 Dec 2020 21:29:44 +0000 (-0800)
Subject: Add configuration so you can develop in a VSCode dev container or Github Codespaces... 
X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=d4335769dbc33b4f8704abe211654ecbd1da1e91;p=advent-of-code-24-elixir.git

Add configuration so you can develop in a VSCode dev container or Github Codespaces (#2)

* Create Dockerfile

* Create devcontainer.json

* Remove extension since elixir 1.7 isnt supported

* Remove port forwarding, not needed for this container

* remove accidental lock file commit

* Remove workspaceFolder config

* Update README.md

* Update README.md

* Set it so Elixir version use be default is latest
---

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 0000000..de3d5fb
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,32 @@
+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/master/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 instal hex and rebar
+  && apt-get install -y build-essential \
+  && mix local.hex --force \
+  && mix local.rebar --force \
+
+  # Clean up
+  && apt-get autoremove -y \
+  && apt-get clean -y \
+  && rm -rf /var/lib/apt/lists/* /tmp/common-setup.sh
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 0000000..7f179c6
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,28 @@
+{
+	"name": "Elixir",
+	"build": {
+		"dockerfile": "Dockerfile",
+		"args": {
+			// Update 'VARIANT' to pick a Elixir version: 1.10
+			"VARIANT": "latest",
+		}
+	},
+	// "workspaceFolder": "/workspace",
+
+	// Set *default* container specific settings.json values on container create.
+	"settings": {
+		"terminal.integrated.shell.linux": "/bin/zsh"
+	},
+
+	// 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.
+	// "forwardPorts": [4000, 4001],
+
+	// 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/README.md b/README.md
index 3ceaa6d..de6e3a9 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ A batteries included starter pack for participating in [Advent of Code](https://
 
 ## Usage
 
-There are 25 modules, 25 tests, and 50 mix tasks. 
+There are 25 modules, 25 tests, and 50 mix tasks.
 
 1. Fill in the tests with the example solutions.
 1. Write your implementation.
@@ -29,7 +29,7 @@ defmodule AdventOfCode.Day01Test do
 
   @tag :skip # Make sure to remove to run your test.
   test "part1" do
-    input = nil 
+    input = nil
     result = part1(input)
 
     assert result
@@ -37,7 +37,7 @@ defmodule AdventOfCode.Day01Test do
 
   @tag :skip # Make sure to remove to run your test.
   test "part2" do
-    input = nil 
+    input = nil
     result = part2(input)
 
     assert result
@@ -62,7 +62,7 @@ defmodule Mix.Tasks.D01.P1 do
         |> part1()
         |> IO.inspect(label: "Part 1 Results")
   end
-end   
+end
 ```
 
 ## Installation
@@ -76,3 +76,22 @@ $ cd advent-of-code
 $ rm -rf .git
 $ git init
 ```
+### Get started coding with zero configuration
+
+#### Using Visual Studio Code
+
+1. [Install Docker Desktop](https://www.docker.com/products/docker-desktop)
+1. Open project directory in VS Code
+1. Press F1, and select `Remote-Containers: Reopen in Container...`
+1. Wait a few minutes as it pulls image down and builds Dev Conatiner Docker image (this should only need to happen once unless you modify the Dockerfile)
+    1. You can see progress of the build by clicking `Starting Dev Container (show log): Building image` that appears in bottom right corner
+    1. During the build process it will also automatically run `mix deps.get`
+1. Once complete VS Code will connect your running Dev Container and will feel like your doing local development
+1. If you would like to use a specific version of Elixir change the `VARIANT` version in `.devcontainer/devcontainer.json`
+1. If you would like more information about VS Code Dev Containers check out the [dev container documentation](https://code.visualstudio.com/docs/remote/create-dev-container/?WT.mc_id=AZ-MVP-5003399)
+
+#### Compatible with Github Codespaces
+1. If you dont have Github Codespaces beta access, sign up for the beta https://github.com/features/codespaces/signup
+1. On GitHub, navigate to the main page of the repository.
+1. Under the repository name, use the  Code drop-down menu, and select Open with Codespaces.
+1. If you already have a codespace for the branch, click  New codespace.