Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr/193 #195

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions Dockerfile.run
Original file line number Diff line number Diff line change
@@ -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} $@"]
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
45 changes: 45 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions docker/build.sh
Original file line number Diff line number Diff line change
@@ -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 \
.
1 change: 1 addition & 0 deletions docker/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
1 change: 1 addition & 0 deletions docker/data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
18 changes: 18 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions start-fmark_dev_env.sh
Original file line number Diff line number Diff line change
@@ -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