From 4be2f7c6c78395e71d2576685a6f4b5bac5cdc8c Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Tue, 31 Mar 2020 19:26:37 +0200 Subject: [PATCH 1/3] [ci] remove build stage (test stage already execute same build) --- .gitlab-ci.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b1b44ea8c..f204f0604 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,4 @@ stages: - - build - test - integration - package @@ -39,13 +38,7 @@ stages: untracked: true paths: - node_modules/ - -build: - <<: *changes - <<: *nvm_env - stage: build - script: - - yarn + #pages: # <<: *nvm_env -- GitLab From fb3cd04c85c92ff6810949d66fedb011182f6bb7 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Tue, 31 Mar 2020 23:54:30 +0200 Subject: [PATCH 2/3] [ci] build docker image in CI --- .gitlab-ci.yml | 56 ++++++++++++++++++++++++++++++++++- package.json | 2 +- release/docker/Dockerfile | 62 +++++++++++++++++++++++++++++++++++++++ release/docker/duniter.sh | 21 +++++++++++++ 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 release/docker/Dockerfile create mode 100644 release/docker/duniter.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f204f0604..9e2c632cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,7 @@ stages: + - package - test - integration - - package - prerelease - release @@ -137,6 +137,60 @@ releases:x64: only: - tags +.docker-build-app-image: + stage: package + image: docker:18.06 + tags: + - redshift-docker-runner + services: + - docker:18.06-dind + before_script: + - docker info + script: + - docker pull $CI_REGISTRY_IMAGE:$IMAGE_TAG || true + - docker build --cache-from $CI_REGISTRY_IMAGE:$IMAGE_TAG --pull -t "$CI_REGISTRY_IMAGE:$IMAGE_TAG" -f release/docker/Dockerfile . + - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY + - docker push "$CI_REGISTRY_IMAGE:$IMAGE_TAG" + +package:test:docker-test-image: + extends: .docker-build-app-image + except: + refs: + - dev + - tags + #when: manual + variables: + IMAGE_TAG: "test-image" + +package:dev:docker: + extends: .docker-build-app-image + only: + refs: + - dev + except: + refs: + - tags + variables: + IMAGE_TAG: "dev" + +package:prod:docker: + stage: package + only: + - tags + image: docker:18.06 + tags: + - redshift-docker-runner + services: + - docker:18.06-dind + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" -f release/docker/Dockerfile . + - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $CI_REGISTRY + - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG" + - docker tag "$CI_REGISTRY_IMAGE:$CI_BUILD_TAG" duniter/duniter + - docker login -u "duniterteam" -p "$DUNITERTEAM_PASSWD" + - docker push duniter/duniter + + .release_jobs: &release_jobs image: rdadev/jinja2:py3.6 tags: diff --git a/package.json b/package.json index e29d139ef..3421b79ce 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "cors": "2.8.2", "daemonize2": "0.4.2", "ddos": "0.1.16", - "dubp-wot-rs": "0.6.0", + "dubp-wot-rs": "0.7.0", "errorhandler": "1.5.0", "event-stream": "3.3.4", "express": "4.15.2", diff --git a/release/docker/Dockerfile b/release/docker/Dockerfile new file mode 100644 index 000000000..6b0b0607a --- /dev/null +++ b/release/docker/Dockerfile @@ -0,0 +1,62 @@ +# ------------------------------------------------------------------------------ +# Build Stage +# ------------------------------------------------------------------------------ + +FROM node:10-alpine as build + +LABEL maintainer="elois <elois@duniter.org>" +LABEL version="0.1.0" +LABEL description="Duniter server (Crypto-currency software to manage libre currency such as Ğ1)" + +ARG DUNITER_UI_VER="1.7.x" + +RUN apk update && \ + apk add ca-certificates curl && \ + update-ca-certificates && \ + apk add --update python make g++ + +# copy source tree +COPY ./ ./ + +# install latest stable rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y + +# build duniter +RUN export PATH="$HOME/.cargo/bin:$PATH" && \ + export RUSTFLAGS="-C target-feature=-crt-static" && \ + yarn install --production && \ + yarn add duniter-ui@${DUNITER_UI_VER} && \ + rm -rf test + +# ------------------------------------------------------------------------------ +# Final Stage +# ------------------------------------------------------------------------------ + +FROM node:10-alpine + +# create group and user duniter +RUN addgroup -S -g 1111 duniter && \ + adduser -SD -h /duniter -G duniter -u 1111 duniter +RUN mkdir -p /var/lib/duniter /etc/duniter && chown duniter:duniter /var/lib/duniter /etc/duniter + +# copy the build artifact from the build stage +COPY --from=build --chown=duniter:duniter . /duniter/duniter + +# copy bootstrap script +RUN cp /duniter/duniter/release/docker/duniter.sh /usr/bin/duniter && \ + chmod +x /usr/bin/duniter && \ + chown duniter:duniter /usr/bin/duniter + +# create volumes +VOLUME /var/lib/duniter +VOLUME /etc/duniter + +# expose ports +EXPOSE 9220 10901 20901 + +# use duniter user +USER duniter +WORKDIR /duniter + +ENTRYPOINT ["/usr/bin/duniter"] +CMD [] diff --git a/release/docker/duniter.sh b/release/docker/duniter.sh new file mode 100644 index 000000000..270d084bb --- /dev/null +++ b/release/docker/duniter.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# Without parameters, start with web interface +if [[ -z ${1} ]]; then + set -- direct_webstart +fi + +# Options +DUNITER_OPTS= +DUNITER_OPTS="${DUNITER_OPTS} --webmhost 0.0.0.0" +DUNITER_OPTS="${DUNITER_OPTS} --home /var/lib/duniter" +DUNITER_OPTS="${DUNITER_OPTS} --mdb duniter_default" + +# Key file found +if [[ -f /etc/duniter/key.yml ]]; then + DUNITER_OPTS="${DUNITER_OPTS} --keyfile /etc/duniter/keys.yml" +fi + +# Start duniter +cd /duniter/duniter/ +bin/duniter ${DUNITER_OPTS} "$@" -- GitLab From a8fa1990454420bda2a9e65a0fd5a1bbe23e685a Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Thu, 2 Apr 2020 01:03:44 +0200 Subject: [PATCH 3/3] [docs] add docker documentation --- README.md | 2 ++ doc/docker.md | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 doc/docker.md diff --git a/README.md b/README.md index 670161a40..0a5c460c9 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ See [Install a node documentation](https://duniter.org/en/wiki/duniter/install/) Visit [Duniter website](https://duniter.org): it gathers theoretical informations, FAQ and several useful links. If you want to learn, this is the first place to visit. +For technical documentation, refer to the `doc` folder of this git repository. + ### Talk about/get involved in Duniter project If you wish to participate/debate on Duniter, you can: diff --git a/doc/docker.md b/doc/docker.md new file mode 100644 index 000000000..1b660f5f2 --- /dev/null +++ b/doc/docker.md @@ -0,0 +1,66 @@ +# Docker image for Duniter + +## Building + +Build this image: + + docker build . -t duniter/duniter + +## Usage + +Start the node: + + docker run -d -p127.0.0.1:9220:9220 -p10901:10901 -p20901:20901 --name duniter duniter/duniter + +You can execute `duniter` commands on the started container, for example: + + docker exec -it duniter duniter wizard key + docker exec -it duniter duniter sync g1.duniter.fr 443 + +You also can open a new terminal on the started container with: + + docker exec -it duniter /bin/sh + +The web UI can be accessed from the host machine by browsing http://localhost:9220. + +Stop the node: + + docker stop duniter + +Restart the stopped node: + + docker start duniter + +## Features + +### Volumes + +The container creates 2 docker volumes. The first one is mounted under `/etc/duniter` and contains the Duniter configuration. The other one is mounted under the Duniter home directory, i.e. `/var/lib/duniter`. This is the place the Duniter database will be stored. + +See more about managing volumes with docker in the [docker documentation](https://docs.docker.com/storage/volumes/). + +If you mount one or more of these directories on your host, be careful that the files must be accessable by the in-image `duniter:duniter` user (uid:gid is 1111:1111). + +### Keyfile + +If the `/etc/duniter/keys.yml` is found on the image, it will automatically be used as keyfile for the server. If you have such a file in your current directory, you can start the node with: + + docker run -d -p127.0.0.1:9220:9220 -p10901:10901 -p20901:20901 --mount src="${PWD}",dst=/etc/duniter --name duniter duniter/duniter + +Note that your file must be readable by the in-image `duniter:duniter` user (uid:gid is 1111:1111). + +### Image parameters + +If you give parameters to the image when creating container, they will be given to the Duniter node. In this case, it will not start the Duniter daemon. Example: + + docker run -it --name duniter duniter/duniter logs + +When no parameters are given, `duniter` is called with the command `direct_webstart`. + +Note that you should not call duniter with daemon command (`webstart` or `start`) if you run docker with `-d` parameter, because the docker image will then immediately stop. + +## Test develop version + +To test develop version on G1-test network: + + docker run -d -p127.0.0.1:9330:9220 -p10900:10900 -p20900:20900 -v $HOME/duniter-docker-home:/var/lib/duniter --name registry.duniter.org nodes/typescript/duniter:dev sync g1-test.duniter.org -- GitLab