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

Fixes #27 [docker] Skycoin VS Code dev image for .NET #29

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docker/images/dev-cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM $IMAGE_FROM

ARG BDATE
ARG SCOMMIT
ARG VS_EXTENSIONS
stdevYuniers marked this conversation as resolved.
Show resolved Hide resolved

# Image labels (see ./hooks/build for ARGS)
LABEL "org.label-schema.name"="libskycoin-dotnet" \
Expand All @@ -17,16 +18,19 @@ LABEL "org.label-schema.name"="libskycoin-dotnet" \
"org.label-schema.usage"="https://github.com/skycoin/libskycoin-dotnet/blob/"$SCOMMIT"/docker/images/dev-cli/README.md" \
"org.label-schema.docker.cmd"="mkdir src; docker run --rm -v ${PWD}/src:/usr/local/src skycoin/skycoindev-dotnet:develop git clone https://github.com/simelo/libskycoin-dotnet.git; sudo chown -R `whoami` src"

# Define some important environment variables
ENV MONO_VERSION 4.8.0.524
ENV DEBIAN_FRONTEND noninteractive

# Add mono debian repo and ins
# Add mono and dotnet repos and install necessary packages
RUN apt update \
&& apt upgrade -y \
&& apt install -y curl \
apt-transport-https \
dirmngr \
&& curl -sSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | apt-key add - \
&& apt-key adv --no-tty --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& echo "deb [arch=amd64] https://packages.microsoft.com/debian/9/prod stretch main" > /etc/apt/sources.list.d/microsoft-dotnet.list \
&& echo "deb https://download.mono-project.com/repo/debian wheezy/snapshots/$MONO_VERSION main" > /etc/apt/sources.list.d/mono-official-stable.list \
&& apt update \
&& apt install -y \
Expand All @@ -37,6 +41,8 @@ RUN apt update \
mono-vbnc \
nuget \
referenceassemblies-pcl \
dotnet-sdk-2.2 \
&& for ext in $VS_EXTENSIONS; do code --user-data-dir $HOME --install-extension $ext; done \
stdevYuniers marked this conversation as resolved.
Show resolved Hide resolved
&& apt clean \
&& rm -rf /var/lib/apt/lists/* /tmp/*

Expand Down
81 changes: 74 additions & 7 deletions docker/images/dev-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

## Simple Tags

- [`develop, dind, vscode, vscode-dind` (*docker/images/dev-cli/Dockerfile*)](https://github.com/simelo/libskycoin-dotnet/blob/develop/docker/images/dev-cli/Dockerfile)
- [`develop, dind, vscode, vscode-dind` (*docker/images/dev-cli/Dockerfile*)](https://github.com/simelo/libskycoin-dotnet/blob/develop/docker/images/dev-cli/Dockerfile)

# Libskycoin .NET CLI development image
## Libskycoin .NET CLI development image

This image has the necessary tools to build, test, edit, lint and version the Libskycoin .NET
source code. It comes with Vim editor installed, along with some plugins
to ease go development and version control with git.

# How to use this image
## How to use this image

## Initialize your development environment.
### Initialize your development environment

```sh
$ mkdir src
Expand All @@ -26,24 +26,91 @@ This downloads the libdotnet source to src/libdotnet and changes the owner
to your user. This is necessary, because all processes inside the container run
as root and the files created by it are therefore owned by root.

## Running commands inside the container
### Running commands inside the container

You can run commands by just passing the them to the image. Everything is run
in a container and deleted when finished.

### Running tests
#### Running tests

```sh
$ docker run --rm \
-v ${PWD}/src:/usr/local/src simelotech/skycoindev-dotnet:develop \
sh -c "cd libskycoin-dotnet; make test"
```

### Editing code
#### Editing code

```sh
$ docker run --rm \
-v ${PWD}/src:/usr/local/src simelotech/skycoindev-dotnet:develop \
vim
```

### Use Visual Studio Code

In order to use Visual Studio Code on development process, please read carefull
the [documentation of oficial Skycoin Visual Studio Code dev image](https://github.com/skycoin/skycoin/tree/develop/docker/images/dev-vscode#initialize-your-development-environment)

#### Installed extensions

- [C#](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
- [C# FixFormat](https://marketplace.visualstudio.com/items?itemName=Leopotam.csharpfixformat)
- [C# Extensions](https://marketplace.visualstudio.com/items?itemName=jchannon.csharpextensions)
- [C# XML Documentation Comments](https://marketplace.visualstudio.com/items?itemName=k--kato.docomment)
- [.NET Core Tools](https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet)

#### Add extensions to Visual Studio Code

Like Skycoin Visual Studio Code dev image, you must pass `VS_EXTENSIONS` environment variable
to the command-line with extensions you prefer. **Pass it if you use a docker image with Visual Studio Code**

```sh
$ docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix \
-v $PWD:/go/src/github.com/simelo/libskycoin-dotnet \
-w $GOPATH/src/github.com/simelo/libskycoin-dotnet \
-e DISPLAY=$DISPLAY \
-e VS_EXTENSIONS="ms-python.python rebornix.Ruby" \
simelotech/skycoindev-dotnet:vscode
```

### Build your own images

The following arguments influence the Docker build process.

- `IMAGE_FROM`: base image used to build libskycoin-dotnet
- `SOURCE_COMMIT`: the SHA1 hash of the commit being tested.
- `IMAGE_NAME`: the name and tag of the Docker repository being built.
- `DOCKERFILE_PATH`: the dockerfile currently being built.
- `VS_EXTENSIONS` Visual Studio Code extensions to add on docker image.

For instance, the following commands can be executed in order to build using `skycoindev-cli:develop` as base image. **Pay attention, you can't use `VS_EXTENSIONS` build arg when base image is only for CLI purpose**

```sh
$ git clone https://github.com/simelo/libskycoin-dotnet.git && cd libskycoin-dotnet
$ IMAGE_FROM="skycoin/skycoindev-cli:develop"
$ SOURCE_COMMIT=$(git rev-parse HEAD)
$ IMAGE_NAME=simelotech/libskycoin-dotnet:develop
$ DOCKERFILE_PATH=docker/images/dev-cli/Dockerfile
$ docker build --build-arg IMAGE_FROM=$IMAGE_FROM \
--build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg SCOMMIT=$SOURCE_COMMIT \
-f $DOCKERFILE_PATH \
-t "$IMAGE_NAME" .
```

If you want use Visual Studio Code as IDE, yo can change `IMAGE_FROM` to build it. **When base image use Visual Studio Code, you can use `VS_EXTENSIONS` build arg**

```sh
$ git clone https://github.com/simelo/libskycoin-dotnet.git && cd libskycoin-dotnet
$ IMAGE_FROM="simelotech/skycoindev-vscode:develop"
$ SOURCE_COMMIT=$(git rev-parse HEAD)
$ IMAGE_NAME=simelotech/libskycoin-dotnet:vscode
$ DOCKERFILE_PATH=docker/images/dev-cli/Dockerfile
$ docker build --build-arg IMAGE_FROM=$IMAGE_FROM \
--build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg SCOMMIT=$SOURCE_COMMIT \
--build-arg VS_EXTENSIONS="ms-vscode.Go windmilleng.vscode-go-autotest" \
-f $DOCKERFILE_PATH \
-t "$IMAGE_NAME" .
```
10 changes: 7 additions & 3 deletions docker/images/dev-cli/hooks/build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# CACHE_TAG: the Docker repository tag being built.
# IMAGE_NAME: the name and tag of the Docker repository being built.
# (This variable is a combination of DOCKER_REPO:CACHE_TAG.)
# VS_EXTENSIONS: Visual Studio Code extensions to add on docker image,
# only if base image is not CLI purpose.

echo "Build hook running"

Expand All @@ -21,23 +23,25 @@ docker build --build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
-t "$IMAGE_NAME" .

# Build :dind, :vscode and :vscode-dind tag
# Only build if
# Only build if docker tag is develop
if [ "$CACHE_TAG" -eq "develop" ]; then
docker build --build-arg IMAGE_FROM="skycoin/skycoindev-cli:dind" \
--build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg SCOMMIT=$SOURCE_COMMIT \
-f $DOCKERFILE_PATH \
-t "$DOCKER_REPO:dind" .

docker build --build-arg IMAGE_FROM="skycoin/skycoindev-vscode:develop" \
docker build --build-arg IMAGE_FROM="simelotech/skycoindev-vscode:develop" \
--build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg SCOMMIT=$SOURCE_COMMIT \
--build-arg VS_EXTENSIONS="ms-vscode.csharp Leopotam.csharpfixformat jchannon.csharpextensions k--kato.docomment formulahendry.dotnet" \
-f $DOCKERFILE_PATH \
-t "$DOCKER_REPO:vscode" .

docker build --build-arg IMAGE_FROM="skycoin/skycoindev-vscode:dind" \
docker build --build-arg IMAGE_FROM="simelotech/skycoindev-vscode:dind" \
--build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg SCOMMIT=$SOURCE_COMMIT \
--build-arg VS_EXTENSIONS="ms-vscode.csharp Leopotam.csharpfixformat jchannon.csharpextensions k--kato.docomment formulahendry.dotnet" \
-f $DOCKERFILE_PATH \
-t "$DOCKER_REPO:vscode-dind" .
fi