diff --git a/Dockerfile.run b/Dockerfile.run new file mode 100644 index 00000000..ca5dba50 --- /dev/null +++ b/Dockerfile.run @@ -0,0 +1,6 @@ +FROM fsharp:netcore +COPY ./FMark /fmark +RUN touch /home/input.fm +RUN dotnet run --project /fmark/src/FMarkCLI /home/test_input.fm + +ENTRYPOINT ["/bin/bash", "-c", "set -e && dotnet run --project /fmark/src/FMarkCLI ${FILE_PATH} $@"] diff --git a/README.md b/README.md index 9393f3c5..13839578 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 $(pwd)/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 diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..15c1fa39 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +FROM fsharp:netcore +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 + +# 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/README.md b/docker/README.md new file mode 100644 index 00000000..09a76405 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,45 @@ +# FMark Dev Docker +Docker environment for FMark dev environment. + +## Build the docker image + +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 + +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). + +* `docker/data` dir contains the vscode settings, extensions & session. +* `Fmark/` dir contains the project code + +## 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/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/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/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..c1ccc3cb --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,18 @@ +#!/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/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