From b7116f7d5c4cfa0a43abf29e5fa8fb0904ccb6c0 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Wed, 25 Sep 2019 14:01:14 +0200 Subject: [PATCH 01/10] Dockerfile.dev still in progress; Dockerfile.server working, may need tidying up/more documentation --- DOCKER_README.md | 7 +++++++ Dockerfile.dev | 17 +++++++++++++++++ Dockerfile.server | 13 +++++++++++++ docker-entrypoint.sh | 11 +++++++++++ 4 files changed, 48 insertions(+) create mode 100644 DOCKER_README.md create mode 100644 Dockerfile.dev create mode 100644 Dockerfile.server create mode 100644 docker-entrypoint.sh diff --git a/DOCKER_README.md b/DOCKER_README.md new file mode 100644 index 00000000..fa8aefe3 --- /dev/null +++ b/DOCKER_README.md @@ -0,0 +1,7 @@ +# Instructions for using Docker + +## dockerfile.server (run vscode in web browser) +``` +docker build -f Dockerfile.server -t fsharp-dev-server . +docker run -p 8443:8443 -dt --rm fsharp-dev-server +``` diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..fa978dc2 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,17 @@ +FROM fsharp + +# Taken from https://code.visualstudio.com/docs/setup/linux +RUN apt-get update && apt-get install -y curl gpg apt-utils +RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg +RUN install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ +RUN sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' +RUN apt-get install -y apt-transport-https +RUN apt-get update +RUN apt-get install -y code # or code-insiders + +# RUN apt update && apt install software-properties-common apt-transport-https wget +# RUN wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - + + +# RUN apt-get update && apt-get install snapd && snap install --classic code +# RUN apt-get update && apt-get install snapd && snap install --classic code diff --git a/Dockerfile.server b/Dockerfile.server new file mode 100644 index 00000000..0de9f85b --- /dev/null +++ b/Dockerfile.server @@ -0,0 +1,13 @@ +FROM fsharp +# Take latest release from https://github.com/cdr/code-server +RUN apt-get update && apt-get install -y wget tar +RUN wget https://github.com/cdr/code-server/releases/download/1.1156-vsc1.33.1/code-server1.1156-vsc1.33.1-linux-x64.tar.gz \ + && tar -xzvf code-server1.1156-vsc1.33.1-linux-x64.tar.gz && mv code-server1.1156-vsc1.33.1-linux-x64 vscode && chmod +x vscode/code-server + +# add in the code folder +# ADD ./code/ /code + +COPY docker-entrypoint.sh /home/ +RUN chmod +x /home/docker-entrypoint.sh + +ENTRYPOINT ["/home/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 00000000..9b4fc107 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# if no extra parameters are passed then start VSCode +# if a parameter is passed than execute that instead +set -e + +if [ $# -eq 0 ] + then + vscode/code-server --allow-http --no-auth --data-dir /data /code + else + exec "$@" +fi From ffe257489bac61d054968ca539f3af32f1beacf0 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Wed, 25 Sep 2019 18:57:01 +0200 Subject: [PATCH 02/10] finalise documentation; remove Dockerfile.dev --- DOCKER_README.md | 16 ++++++++++++++-- Dockerfile.dev | 17 ----------------- 2 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 Dockerfile.dev diff --git a/DOCKER_README.md b/DOCKER_README.md index fa8aefe3..80ceecf3 100644 --- a/DOCKER_README.md +++ b/DOCKER_README.md @@ -1,7 +1,19 @@ # Instructions for using Docker ## dockerfile.server (run vscode in web browser) + +### Build the docker image +`docker build -f Dockerfile.server -t fsharp-dev-server .` + +Requires `docker-entrypoint.sh` in current directory. + +### Run the docker image + +`docker run -p 8443:8443 -dt --rm fsharp-dev-server` + +Now VS Code is available from your browser at [localhost:8443](https://localhost:8443). + +Share folders with your Docker vscode instance by adding the following to the `docker run` command: ``` -docker build -f Dockerfile.server -t fsharp-dev-server . -docker run -p 8443:8443 -dt --rm fsharp-dev-server +-v $(pwd)/data:/data -v $(pwd)/code:/code ``` diff --git a/Dockerfile.dev b/Dockerfile.dev deleted file mode 100644 index fa978dc2..00000000 --- a/Dockerfile.dev +++ /dev/null @@ -1,17 +0,0 @@ -FROM fsharp - -# Taken from https://code.visualstudio.com/docs/setup/linux -RUN apt-get update && apt-get install -y curl gpg apt-utils -RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg -RUN install -o root -g root -m 644 packages.microsoft.gpg /usr/share/keyrings/ -RUN sh -c 'echo "deb [arch=amd64 signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list' -RUN apt-get install -y apt-transport-https -RUN apt-get update -RUN apt-get install -y code # or code-insiders - -# RUN apt update && apt install software-properties-common apt-transport-https wget -# RUN wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - - - -# RUN apt-get update && apt-get install snapd && snap install --classic code -# RUN apt-get update && apt-get install snapd && snap install --classic code From 1db2bad94dacf43d60bc18c29f06c39808f7ff53 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 13:24:26 +0200 Subject: [PATCH 03/10] Update according to ps-george/hlp-docker & move to own folder --- DOCKER_README.md | 19 ------------------- Dockerfile.server | 13 ------------- docker-entrypoint.sh | 11 ----------- docker/Dockerfile | 28 ++++++++++++++++++++++++++++ docker/README.md | 31 +++++++++++++++++++++++++++++++ docker/code/Example.fs | 0 docker/data/.gitignore | 1 + docker/docker-entrypoint.sh | 17 +++++++++++++++++ 8 files changed, 77 insertions(+), 43 deletions(-) delete mode 100644 DOCKER_README.md delete mode 100644 Dockerfile.server delete mode 100644 docker-entrypoint.sh create mode 100644 docker/Dockerfile create mode 100644 docker/README.md create mode 100644 docker/code/Example.fs create mode 100644 docker/data/.gitignore create mode 100644 docker/docker-entrypoint.sh diff --git a/DOCKER_README.md b/DOCKER_README.md deleted file mode 100644 index 80ceecf3..00000000 --- a/DOCKER_README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Instructions for using Docker - -## dockerfile.server (run vscode in web browser) - -### Build the docker image -`docker build -f Dockerfile.server -t fsharp-dev-server .` - -Requires `docker-entrypoint.sh` in current directory. - -### Run the docker image - -`docker run -p 8443:8443 -dt --rm fsharp-dev-server` - -Now VS Code is available from your browser at [localhost:8443](https://localhost:8443). - -Share folders with your Docker vscode instance by adding the following to the `docker run` command: -``` --v $(pwd)/data:/data -v $(pwd)/code:/code -``` diff --git a/Dockerfile.server b/Dockerfile.server deleted file mode 100644 index 0de9f85b..00000000 --- a/Dockerfile.server +++ /dev/null @@ -1,13 +0,0 @@ -FROM fsharp -# Take latest release from https://github.com/cdr/code-server -RUN apt-get update && apt-get install -y wget tar -RUN wget https://github.com/cdr/code-server/releases/download/1.1156-vsc1.33.1/code-server1.1156-vsc1.33.1-linux-x64.tar.gz \ - && tar -xzvf code-server1.1156-vsc1.33.1-linux-x64.tar.gz && mv code-server1.1156-vsc1.33.1-linux-x64 vscode && chmod +x vscode/code-server - -# add in the code folder -# ADD ./code/ /code - -COPY docker-entrypoint.sh /home/ -RUN chmod +x /home/docker-entrypoint.sh - -ENTRYPOINT ["/home/docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100644 index 9b4fc107..00000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# if no extra parameters are passed then start VSCode -# if a parameter is passed than execute that instead -set -e - -if [ $# -eq 0 ] - then - vscode/code-server --allow-http --no-auth --data-dir /data /code - else - exec "$@" -fi diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..d5b6d6eb --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,28 @@ +FROM fsharp +RUN apt-get update && apt-get install -y wget tar gpg + +# Install vscode +# Take latest release from https://github.com/cdr/code-server/releases/latest +RUN wget https://github.com/cdr/code-server/releases/download/1.1156-vsc1.33.1/code-server1.1156-vsc1.33.1-linux-x64.tar.gz \ + && tar -xzvf code-server1.1156-vsc1.33.1-linux-x64.tar.gz && mv code-server1.1156-vsc1.33.1-linux-x64 /usr/local/bin/vscode && chmod +x /usr/local/bin/vscode/code-server + +# Install nvm +ENV NVM_DIR /home/.nvm +RUN mkdir -p $NVM_DIR +ENV NODE_VERSION 12.11.0 +RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash \ + && . $NVM_DIR/nvm.sh \ + && nvm install $NODE_VERSION \ + && nvm alias default $NODE_VERSION \ + && nvm use default \ + && apt-get install -y --no-install-recommends yarn +ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules +ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH + +# Install gosu +RUN apt-get install -y gosu + +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..eed12f54 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,31 @@ +# FMark Dev Docker +Docker environment for FMark dev environment. + +## Build the docker image +`docker build -f Dockerfile -t fmark-dev .` + +Requires `docker-entrypoint.sh` in current directory. + +## Run the docker image + +``` +docker run -p 8443:8443 -e LOCAL_USER_ID=`id -u $USER` -v $(pwd)/data:/home/dockeruser/data -v $(pwd)/code:/home/dockeruser/code -dt --rm fmark-dev +``` + +Now VS Code is available from your browser at [localhost:8443](https://localhost:8443). + +The `data` dir contains the vscode settings, extensions & session. + +## Sharing additional directories + +Share additional directories with your Docker vscode instance by adding the following to the `docker run` command: +``` +-v $(pwd)/directory:/home/directory +``` + +## Dependencies included + +- fsharp via the [official fsharp docker image](https://hub.docker.com/_/fsharp) +- vscode server 1.1156-vsc1.33.1. Check https://github.com/cdr/code-server/releases/latest for update. +- [nvm](https://github.com/nvm-sh/nvm) Node version manager +- [yarn](https://yarnpkg.com/lang/en/) Yarn package manager diff --git a/docker/code/Example.fs b/docker/code/Example.fs new file mode 100644 index 00000000..e69de29b diff --git a/docker/data/.gitignore b/docker/data/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/docker/data/.gitignore @@ -0,0 +1 @@ +* diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100644 index 00000000..1745be27 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# if no extra parameters are passed then start VSCode +# if a parameter is passed than execute that instead +set -e + +# Add local user +# Either use the LOCAL_USER_ID if passed in at runtime or fallback +USER_ID=${LOCAL_USER_ID:-9001} +echo "Starting with UID : $USER_ID" +useradd --shell /bin/bash -u $USER_ID -o -c "" -m dockeruser + +if [ $# -eq 0 ] + then + gosu dockeruser /usr/local/bin/vscode/code-server --allow-http --no-auth --user-data-dir /home/data /home/code + else + exec gosu dockeruser "$@" +fi From 8f76d9eba24a1d8db71fd86752f6757cd603ed65 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 17:15:09 +0200 Subject: [PATCH 04/10] Remove Example.fs and replace with .gitignore --- docker/code/.gitignore | 1 + docker/code/Example.fs | 0 2 files changed, 1 insertion(+) create mode 100644 docker/code/.gitignore delete mode 100644 docker/code/Example.fs diff --git a/docker/code/.gitignore b/docker/code/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/docker/code/.gitignore @@ -0,0 +1 @@ +* diff --git a/docker/code/Example.fs b/docker/code/Example.fs deleted file mode 100644 index e69de29b..00000000 From f0a6fe1c0817c05d58c6b747103168c80f56a41a Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 19:18:34 +0200 Subject: [PATCH 05/10] Switch base image to fsharp:netcore (this image actually has dotnet) --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index d5b6d6eb..21d662fe 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM fsharp +FROM fsharp:netcore RUN apt-get update && apt-get install -y wget tar gpg # Install vscode From dd644919ed4f0e0135850d0bcf4b87e0471b4000 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 19:19:07 +0200 Subject: [PATCH 06/10] Add Dockerfile that creates image that 'just runs' FMark CLI --- Dockerfile.run | 7 +++++++ README.md | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Dockerfile.run diff --git a/Dockerfile.run b/Dockerfile.run new file mode 100644 index 00000000..79a0cb22 --- /dev/null +++ b/Dockerfile.run @@ -0,0 +1,7 @@ +FROM fsharp:netcore +RUN apt-get update && apt-get install -y gosu +COPY FMark /home/FMark +RUN touch /home/input.fm +RUN dotnet run --project /home/FMark/src/FMarkCLI /home/test_input.fm + +ENTRYPOINT ["/bin/bash", "-c", "set -e && dotnet run --project /home/FMark/src/FMarkCLI ${FILE_PATH} $@"] diff --git a/README.md b/README.md index 9393f3c5..5369bbd5 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,32 @@ OPTIONS: ``` Note: Markdown generation is incomplete and should only be used for property based testing. +### Run CLI via Docker + +``` +# Build/pull docker image +docker build -f Dockerfile.run -t fmark-run . +docker run -e "FILE_PATH=/home/examples/example.fmark" -v examples:/home/examples -it fmark-run +``` + +Or create a bash function for yourself, e.g. + +```bash +fmark () { + if [ -f $1 ] ; then + FILE_DIR=`dirname $1` + FILE_NAME=`basename $1` + CWD=`pwd` + shift + echo "Processing $FILE_NAME in $CWD/$FILE_DIR" + docker run -e "FILE_PATH=/home/$FILE_DIR/$FILE_NAME" -v $CWD/$FILE_DIR:/home/$FILE_DIR -it fmark-run $@ + fi +} +``` + +Note, when referring to file paths in additional arguments, must think in the context of the Docker file structure, e.g: + +`fmark examples/example.fmark --output /home/examples/test.html` will save to `examples/test.html`. # Modules From 29a7eda991974decbf97ff313b38889ffb33f4b7 Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 19:22:00 +0200 Subject: [PATCH 07/10] Correct docker command with one that actually works --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5369bbd5..13839578 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Note: Markdown generation is incomplete and should only be used for property bas ``` # Build/pull docker image docker build -f Dockerfile.run -t fmark-run . -docker run -e "FILE_PATH=/home/examples/example.fmark" -v examples:/home/examples -it fmark-run +docker run -e "FILE_PATH=/home/examples/example.fmark" -v $(pwd)/examples:/home/examples -it fmark-run ``` Or create a bash function for yourself, e.g. From 31260a622c36aa915aea6f03967ba5d784cd382d Mon Sep 17 00:00:00 2001 From: "@ps-george" <17267419+ps-george@users.noreply.github.com> Date: Thu, 26 Sep 2019 19:27:08 +0200 Subject: [PATCH 08/10] Patch. Wasn't working outside fmark dir. Now it does. --- Dockerfile.run | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile.run b/Dockerfile.run index 79a0cb22..ca5dba50 100644 --- a/Dockerfile.run +++ b/Dockerfile.run @@ -1,7 +1,6 @@ FROM fsharp:netcore -RUN apt-get update && apt-get install -y gosu -COPY FMark /home/FMark +COPY ./FMark /fmark RUN touch /home/input.fm -RUN dotnet run --project /home/FMark/src/FMarkCLI /home/test_input.fm +RUN dotnet run --project /fmark/src/FMarkCLI /home/test_input.fm -ENTRYPOINT ["/bin/bash", "-c", "set -e && dotnet run --project /home/FMark/src/FMarkCLI ${FILE_PATH} $@"] +ENTRYPOINT ["/bin/bash", "-c", "set -e && dotnet run --project /fmark/src/FMarkCLI ${FILE_PATH} $@"] From 166be17681f7d41d79ca8b78c1607b9a6a709522 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 2 Oct 2019 21:18:08 +0100 Subject: [PATCH 09/10] fix and enhance fmark-dev --- docker/Dockerfile | 5 +++++ docker/build.sh | 7 +++++++ docker/docker-entrypoint.sh | 3 ++- start-fmark_dev_env.sh | 13 +++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100755 docker/build.sh create mode 100755 start-fmark_dev_env.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 21d662fe..15c1fa39 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,4 +25,9 @@ RUN apt-get install -y gosu COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# make home dir writable for everybody +# containerized, no security implications +ENV DU_HOME /home/dockeruser +RUN mkdir -p $DU_HOME && chmod 777 $DU_HOME + ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/docker/build.sh b/docker/build.sh new file mode 100755 index 00000000..4412b8c8 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + + +docker build -f Dockerfile \ + -t zestylogic/fmark-dev:$(date +"%F-%H-%M-%S") \ + -t zestylogic/fmark-dev:latest \ + . diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 1745be27..c1ccc3cb 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -11,7 +11,8 @@ useradd --shell /bin/bash -u $USER_ID -o -c "" -m dockeruser if [ $# -eq 0 ] then - gosu dockeruser /usr/local/bin/vscode/code-server --allow-http --no-auth --user-data-dir /home/data /home/code + gosu dockeruser /usr/local/bin/vscode/code-server --allow-http --no-auth \ + --user-data-dir /home/dockeruser/data /home/dockeruser/code else exec gosu dockeruser "$@" fi diff --git a/start-fmark_dev_env.sh b/start-fmark_dev_env.sh new file mode 100755 index 00000000..442cacfa --- /dev/null +++ b/start-fmark_dev_env.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# not using -d because the user might not aware the server is still running after +# a long hacking session +# plus detaching does not give the user console output from the container which +# might be useful +# option -i, interactive, so that Ctrl+C can be received by the container, therefore +# exiting the container, and trigger --rm action +# option -t. provide tty +docker run -it --rm -p 8443:8443 -e LOCAL_USER_ID=`id -u $USER` \ + -v $(pwd)/docker/data:/home/dockeruser/data \ + -v $(pwd)/FMark:/home/dockeruser/code \ + zestylogic/fmark-dev:latest From 5c6753f463ec890693e4ea82fa7fc44f1b4986b8 Mon Sep 17 00:00:00 2001 From: Mike Chen Date: Wed, 2 Oct 2019 21:34:43 +0100 Subject: [PATCH 10/10] update README --- docker/README.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/docker/README.md b/docker/README.md index eed12f54..09a76405 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,19 +2,33 @@ Docker environment for FMark dev environment. ## Build the docker image -`docker build -f Dockerfile -t fmark-dev .` + +run `build.sh` Requires `docker-entrypoint.sh` in current directory. +The command will build a docker image with 2 tags in the same repo, +__zestylogic/fmark-dev__, +* current build date and time +* "latest" + +So every time `build.sh` is run, the "latest" tag will be overwritten +and a new, unique *version* number will also be generated. + +Then the image can be easily published to DockerHub by +`docker push zestylogic/fmark-dev` +given the user have access to zestylogic account +(use `docker login`). + + ## Run the docker image -``` -docker run -p 8443:8443 -e LOCAL_USER_ID=`id -u $USER` -v $(pwd)/data:/home/dockeruser/data -v $(pwd)/code:/home/dockeruser/code -dt --rm fmark-dev -``` +From the FMark root directory, run `start-fmark_dev_env.sh` Now VS Code is available from your browser at [localhost:8443](https://localhost:8443). -The `data` dir contains the vscode settings, extensions & session. +* `docker/data` dir contains the vscode settings, extensions & session. +* `Fmark/` dir contains the project code ## Sharing additional directories