diff --git a/docker/images/dev-cli/Dockerfile b/docker/images/dev-cli/Dockerfile index 8caf6c53..344d3702 100644 --- a/docker/images/dev-cli/Dockerfile +++ b/docker/images/dev-cli/Dockerfile @@ -39,12 +39,21 @@ RUN set -ex \ wget \ python-pip \ python3-pip \ - && pip install --upgrade pip \ - && pip3 install --upgrade pip + && pip install --upgrade pip virtualenv \ + && pip3 install --upgrade pip virtualenv \ + && mkdir -p /srv/venv/pysky27 \ + && mkdir -p /srv/venv/pysky34 \ + && mkdir -p /srv/venv/pysky35 \ + && mkdir -p /srv/venv/pysky36 \ + && mkdir -p /srv/venv/pysky37 \ + && virtualenv -p python2.7 /srv/venv/pysky27 \ + && /bin/bash -c "source /srv/venv/pysky27/bin/activate && pip install pyskycoin && deactivate" \ + && virtualenv -p python3.5 /srv/venv/pysky35 \ + && /bin/bash -c "source /srv/venv/pysky35/bin/activate && pip install pyskycoin && deactivate" # Install Python 3.7 # runtime dependencies -ENV PYTHON_VERSION 3.7.1 +ENV PYTHON_VERSION="3.7.2" RUN set -ex \ && buildDeps=" \ libexpat1-dev \ @@ -55,14 +64,14 @@ RUN set -ex \ " \ && apt-get install -y $buildDeps --no-install-recommends \ \ - && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ + && wget -qO python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ + && wget -qO python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && for server in ha.pool.sks-keyservers.net \ hkp://p80.pool.sks-keyservers.net:80 \ keyserver.ubuntu.com \ hkp://keyserver.ubuntu.com:80 ;do\ - gpg --keyserver "$server" --recv-keys 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D;done \ + gpg --no-tty -q --keyserver "$server" --recv-keys 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D;done \ && gpg --batch --verify python.tar.xz.asc python.tar.xz \ && rm -rf "$GNUPGHOME" python.tar.xz.asc \ && mkdir -p /usr/src/python \ @@ -93,7 +102,7 @@ RUN set -ex \ # Install Python 3.6 # runtime dependencies -ENV PYTHON_VERSION 3.6.7 +ENV PYTHON_VERSION="3.6.8" RUN set -ex \ && buildDeps=" \ libexpat1-dev \ @@ -104,14 +113,14 @@ RUN set -ex \ " \ && apt-get install -y $buildDeps --no-install-recommends \ \ - && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ + && wget -qO python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ + && wget -qO python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && for server in ha.pool.sks-keyservers.net \ hkp://p80.pool.sks-keyservers.net:80 \ keyserver.ubuntu.com \ hkp://keyserver.ubuntu.com:80 ;do\ - gpg --keyserver "$server" --recv-keys 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D;done \ + gpg --no-tty -q --keyserver "$server" --recv-keys 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D;done \ && gpg --batch --verify python.tar.xz.asc python.tar.xz \ && rm -rf "$GNUPGHOME" python.tar.xz.asc \ && mkdir -p /usr/src/python \ @@ -142,7 +151,7 @@ RUN set -ex \ # Install Python 3.4 # runtime dependencies -ENV PYTHON_VERSION 3.4.9 +ENV PYTHON_VERSION="3.4.9" RUN set -ex \ && buildDeps=" \ # as of Stretch, "gpg" is no longer included by default @@ -150,14 +159,14 @@ RUN set -ex \ " \ && apt-get install -y libssl1.0-dev $buildDeps --no-install-recommends \ \ - && wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ + && wget -qO python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ + && wget -qO python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ && export GNUPGHOME="$(mktemp -d)" \ && for server in ha.pool.sks-keyservers.net \ hkp://p80.pool.sks-keyservers.net:80 \ keyserver.ubuntu.com \ hkp://keyserver.ubuntu.com:80 ;do\ - gpg --keyserver "$server" --recv-keys 97FC712E4C024BBEA48A61ED3A5CA953F73C700D;done \ + gpg --no-tty -q --keyserver "$server" --recv-keys 97FC712E4C024BBEA48A61ED3A5CA953F73C700D;done \ && gpg --batch --verify python.tar.xz.asc python.tar.xz \ && rm -rf "$GNUPGHOME" python.tar.xz.asc \ && mkdir -p /usr/src/python \ @@ -191,7 +200,7 @@ RUN set -ex \ && rm -rf /usr/src/python # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value ''" -ENV PYTHON_PIP_VERSION 18.1 +ENV PYTHON_PIP_VERSION="18.1" RUN set -ex; \ \ wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \ @@ -225,11 +234,18 @@ RUN set -ex; \ rm -f get-pip.py # Install packages in PIP_PACKAGES +# Create python virtualenv with pyskycoin pre-installed RUN pip install --upgrade $PIP_PACKAGES \ && pip3 install --upgrade $PIP_PACKAGES \ - && python3.4 -m pip install --upgrade $PIP_PACKAGES \ - && python3.6 -m pip install --upgrade $PIP_PACKAGES \ - && python3.7 -m pip install --upgrade $PIP_PACKAGES + && python3.4 -m pip install --upgrade $PIP_PACKAGES \ + && python3.6 -m pip install --upgrade $PIP_PACKAGES \ + && python3.7 -m pip install --upgrade $PIP_PACKAGES \ + && virtualenv -p python3.4 /srv/venv/pysky34 \ + && /bin/bash -c "source /srv/venv/pysky34/bin/activate && pip install pyskycoin && deactivate" \ + && virtualenv -p python3.6 /srv/venv/pysky36 \ + && /bin/bash -c "source /srv/venv/pysky36/bin/activate && pip install pyskycoin && deactivate" \ + && virtualenv -p python3.7 /srv/venv/pysky37 \ + && /bin/bash -c "source /srv/venv/pysky37/bin/activate && pip install pyskycoin && deactivate" WORKDIR $GOPATH/src/github.com/skycoin diff --git a/docker/images/dev-cli/README.md b/docker/images/dev-cli/README.md index e856c5b9..046a9077 100644 --- a/docker/images/dev-cli/README.md +++ b/docker/images/dev-cli/README.md @@ -2,10 +2,9 @@ ## Simple Tags -- [`develop` (*docker/images/dev/Dockerfile*)](https://github.com/simelo/pyskycoin/blob/develop/docker/images/dev/Dockerfile) -- [`dind` (*docker/images/dev/Dockerfile*)](https://github.com/simelo/pyskycoin/blob/develop/docker/images/dev/Dockerfile) +- [`develop, dind, vscode, vscode-dind` (*docker/images/dev-cli/Dockerfile*)](https://github.com/skycoin/pyskycoin/blob/develop/docker/images/dev-cli/Dockerfile) -# Pyskycoin CLI/DIND development image +## Pyskycoin CLI/DIND development image This image (CLI) has the necessary tools to build, test, edit, lint and version the Pyskycoin source code. It comes with some versions of Python (2.7, 3.4, 3.5 and 3.6) and with Vim editor installed, along with some plugins @@ -14,15 +13,15 @@ to ease go development and version control with git. Besides it is possible to use Docker in Docker (DIND) Pyskycoin development image, it is based on `skycoin/skycoindev-cli:dind` and provides all tools included in Pyskycoin CLI image. -# How to use this image +## How to use this image -## Initialize your development environment. +## Initialize your development environment ```sh $ mkdir src $ docker run --rm \ -v ${PWD}/src:/usr/local/src skycoin/skycoindev-python:develop \ - git clone https://github.com/simelo/pyskycoin.git \ + git clone https://github.com/skycoin/pyskycoin.git \ $ sudo chown -R `whoami` src ``` @@ -30,6 +29,21 @@ This downloads the pyskycoin source to src/pyskycoin 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. +## Pre-installed pip packages + +In order to provide a good development environment for you, some pip packages has been installed: + +- [setuptools](https://pypi.org/project/setuptools/) +- [wheel](https://pypi.org/project/wheel/) +- [tox](https://pypi.org/project/tox/) +- [tox-pyenv](https://pypi.org/project/tox-pyenv/) +- [tox-travis](https://pypi.org/project/tox-travis/) +- [pytest](https://pypi.org/project/pytest/) +- [pytest-runner](https://pypi.org/project/pytest-runner/) +- [virtualenv](https://pypi.org/project/virtualenv/) +- [pylint](https://pypi.org/project/pylint/) +- [flake8](https://pypi.org/project/flake8/) + ## Running commands inside the container You can run commands by just passing them to the image. Everything is run @@ -56,7 +70,8 @@ $ docker run --rm \ ### Start a daemon instance ```sh -$ docker run --privileged --name some-name -d skycoin/skycoindev-python:dind +$ docker run --privileged --name some-name \ + -d skycoin/skycoindev-python:dind ``` ### Where to store data @@ -70,41 +85,91 @@ The downside is that you need to make sure that the directory exists, and that e ```sh $ docker run --privileged --name some-name \ - -v /my/own/var-lib-docker:/var/lib/docker \ + -v /my/own/var-lib-docker:/var/lib/docker \ -d skycoin/skycoindev-python:dind ``` -# Build your own images +### 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) + +#### Pre-installed extensions + +- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) +- [Python Docstring](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring) +- [Trailing Spaces](https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces) + +#### 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/skycoin/pyskycoin \ + -w $GOPATH/src/github.com/skycoin/pyskycoin \ + -e DISPLAY=$DISPLAY \ + -e VS_EXTENSIONS="ms-python.python rebornix.Ruby" \ + skycoindev-python:vscode +``` + +## Build your own images The build process relies on the following parameters - `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. +- `PIP_PACKAGES`: pip packages to install inside docker image. +- `VS_EXTENSIONS` Visual Studio Code extensions to add on docker image. In order to build image from `skycoindev-cli:develop` execute the following shell command ```sh -$ cd skycoin +$ cd pyskycoin $ SOURCE_COMMIT=$(git rev-parse HEAD) $ IMAGE_NAME=skycoin/skycoindev-python:develop -$ DOCKERFILE_PATH=docker/images/dev/Dockerfile +$ DOCKERFILE_PATH=docker/images/dev-cli/Dockerfile $ docker build --build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ --build-arg SCOMMIT=$SOURCE_COMMIT \ + --build-arg PIP_PACKAGES="Twisted tox" \ -f $DOCKERFILE_PATH \ -t "$IMAGE_NAME" . ``` -If you prefer to use `skycoindev-cli:dind` then run: +If do you prefer to use `skycoindev-cli:dind` then run: ```sh -$ cd skycoin +$ cd pyskycoin +$ IMAGE_FROM="skycoin/skycoindev-cli:dind" $ SOURCE_COMMIT=$(git rev-parse HEAD) $ IMAGE_NAME=skycoin/skycoindev-python:dind -$ DOCKERFILE_PATH=docker/images/dev/Dockerfile -$ docker build --build-arg IMAGE_FROM="skycoin/skycoindev-cli:dind" \ +$ 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 PIP_PACKAGES="Twisted tox" \ + -f $DOCKERFILE_PATH \ + -t "$IMAGE_NAME" . +``` + +Nevertheless, if do you like use Visual Studio Code instead of CLI, you can change `IMAGE_FROM` to build it. **When base image use Visual Studio Code, you can use `VS_EXTENSIONS` build arg** + +```sh +$ cd pyskycoin +$ git submodule update --init --recursive +$ # Move to vscode folder to avoid file errors with vscode docker image +$ cd gopath/src/github.com/skycoin/skycoin/docker/images/dev-vscode/ +$ IMAGE_FROM="skycoin/skycoindev-python:develop" +$ SOURCE_COMMIT=$(git rev-parse HEAD) +$ IMAGE_NAME=skycoin/skycoindev-python: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 PIP_PACKAGES="matplotlib tox" \ + --build-arg VS_EXTENSIONS="almenon.arepl ms-python.python" \ -f $DOCKERFILE_PATH \ -t "$IMAGE_NAME" . ``` @@ -116,4 +181,3 @@ and `master` branch on every push made after merging. The same process is triggered for all feature branches matching the pattern `/^([^_]+)_t([0-9]+)_.*docker.*/`. The tag generated for such images will be of the form `feature-{\1}-{\2}`. - diff --git a/docker/images/dev-cli/hooks/build b/docker/images/dev-cli/hooks/build index 326e811e..e3f85d0a 100644 --- a/docker/images/dev-cli/hooks/build +++ b/docker/images/dev-cli/hooks/build @@ -12,24 +12,46 @@ # IMAGE_NAME: the name and tag of the Docker repository being built. # (This variable is a combination of DOCKER_REPO:CACHE_TAG.) # PIP_PACKAGES: pip packages to install inside docker image. +# VS_EXTENSIONS: Visual Studio Code extensions to add on docker image, +# only if base image is not CLI purpose. echo "Build hook running" -pwd +cd ../../../ # Build :develop tag docker build --build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ --build-arg SCOMMIT=$SOURCE_COMMIT \ - --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner" \ + --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner virtualenv pylint flake8" \ -f $DOCKERFILE_PATH \ -t "$IMAGE_NAME" . -# Build :dind tag -if [ "$CACHE_TAG" -eq "develop" ]; then - docker build --build-arg IMAGE_FROM="skycoin/skycoindev-cli:dind" \ +# Build :dind, :vscode and :vscode-dind tag +# Only build if docker tag is develop +if [ "$CACHE_TAG" == "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 \ - --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner" \ + --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner virtualenv pylint flake8" \ -f $DOCKERFILE_PATH \ -t "$DOCKER_REPO:dind" . + + # Move to vscode folder to avoid file errors with vscode docker image + cd gopath/src/github.com/skycoin/skycoin/docker/images/dev-vscode/ + + docker build --build-arg IMAGE_FROM="$IMAGE_NAME" \ + --build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + --build-arg SCOMMIT=$SOURCE_COMMIT \ + --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner virtualenv pylint flake8" \ + --build-arg VS_EXTENSIONS="ms-python.python njpwerner.autodocstring shardulm94.trailing-spaces VisualStudioExptTeam.vscodeintellicode" \ + -f Dockerfile \ + -t "$DOCKER_REPO:vscode" . + + docker build --build-arg IMAGE_FROM="$DOCKER_REPO:dind" \ + --build-arg BDATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ + --build-arg SCOMMIT=$SOURCE_COMMIT \ + --build-arg PIP_PACKAGES="setuptools wheel tox tox-pyenv tox-travis pytest pytest-runner virtualenv pylint flake8" \ + --build-arg VS_EXTENSIONS="ms-python.python njpwerner.autodocstring shardulm94.trailing-spaces VisualStudioExptTeam.vscodeintellicode" \ + -f Dockerfile \ + -t "$DOCKER_REPO:vscode-dind" . fi diff --git a/docker/images/dev-cli/hooks/push b/docker/images/dev-cli/hooks/push index f9e243fc..3ae43b49 100644 --- a/docker/images/dev-cli/hooks/push +++ b/docker/images/dev-cli/hooks/push @@ -2,6 +2,8 @@ docker push $IMAGE_NAME -if [ "$CACHE_TAG" -eq "develop" ]; then - docker push $DOCKER_REPO:dind +if [ "$CACHE_TAG" == "develop" ]; then + docker push "$DOCKER_REPO:dind" + docker push "$DOCKER_REPO:vscode" + docker push "$DOCKER_REPO:vscode-dind" fi