Skip to content

A peer-to-peer stack for code collaboration

Build a working image of radicle-server

Thomas Scholtes0c5f19ccd2e6
diff --git a/README.md b/README.md
index a977ea0..0d3450e 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,16 @@ rad> (def-rec fac (fn [n] (if (eq? n 0) 1 (* n (fac (- n 1))))))
rad> (fac 6)
```
+## Radicle Server
+
+`radicle-server` is a service that hosts Radicle state machines and persists
+them to PostgreSQL.
+
+The lastest master build of this service is distributed as the Docker image
+`eu.gcr.io/opensourcecoin/radicle-server`. To build the image locally run
+`images/radicle-server/build.sh`. You can also use
+`images/radicle-server/docker-compose.yaml`.
+
## Development
You can run tests with `stack test`.
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
index 19a7697..a09a555 100644
--- a/cloudbuild.yaml
+++ b/cloudbuild.yaml
@@ -6,6 +6,8 @@ steps:
args:
- '-c'
- |
+ set -euxo pipefail
+
source scripts/ci.sh
load-cache
@@ -16,8 +18,8 @@ steps:
args:
- '-c'
- |
- stack config set system-ghc --global true
- stack config set install-ghc --global false
+ set -euxo pipefail
+
stack install stylish-haskell hlint weeder
- id: "Format"
@@ -30,31 +32,39 @@ steps:
env: ['STACK_ROOT=/workspace/.stack']
args: ['stack', 'exec', '--', 'hlint', '.']
- - id: "Test & Build"
+ - id: "Build & Test"
name: 'haskell:8.4.3'
env: ['STACK_ROOT=/workspace/.stack']
entrypoint: bash
args:
- '-c'
- |
- apt-get update
- apt-get -y install postgresql libpq-dev
+ set -euxo pipefail
+
+ apt-get -qq update
+ apt-get -yqq install libpq-dev
+ stack build --fast
stack build --fast --test --no-terminal --pedantic
+ ./images/radicle-server/ci-copy-bin.sh
+
- id: "Lint (weeder)"
- waitFor: ["Test & Build"]
+ waitFor: ["Build & Test"]
name: 'haskell:8.4.3'
env: ["STACK_ROOT=/workspace/.stack"]
args: ["stack", "exec", "--", "weeder", "--match"]
- id: "Build reference document"
- waitFor: ["Test & Build"]
+ waitFor:
+ - "Build & Test"
name: 'haskell:8.4.3'
env: ['STACK_ROOT=/workspace/.stack']
entrypoint: bash
args:
- '-c'
- |
+ set -euxo pipefail
+
mv docs/source/reference.rst oldref
stack exec radicle-ref-doc
if ! (diff oldref docs/source/reference.rst); then
@@ -62,12 +72,36 @@ steps:
exit 1
fi
+ - id: "Build radicle-server image"
+ waitFor:
+ - "Build & Test"
+ name: 'gcr.io/cloud-builders/docker'
+ entrypoint: bash
+ env:
+ - BRANCH_NAME=$BRANCH_NAME
+ args:
+ - "-c"
+ - |
+ set -euxo pipefail
+
+ if [ "$BRANCH_NAME" == "master" ]; then
+ image_name="eu.gcr.io/opensourcecoin/radicle-server"
+ docker build \
+ --tag "$image_name" \
+ --cache-from "$image_name" \
+ ./images/radicle-server
+ docker push "$image_name"
+ fi
+
- id: "Save cache"
+ waitFor:
+ - "Build & Test"
name: gcr.io/cloud-builders/gsutil
entrypoint: 'bash'
args:
- '-c'
- |
+ set -euxo pipefail
+
source scripts/ci.sh
save-cache
-
diff --git a/images/radicle-server/.dockerignore b/images/radicle-server/.dockerignore
new file mode 100644
index 0000000..720e3c1
--- /dev/null
+++ b/images/radicle-server/.dockerignore
@@ -0,0 +1,2 @@
+*
+!/bin
diff --git a/images/radicle-server/.gitignore b/images/radicle-server/.gitignore
new file mode 100644
index 0000000..5e56e04
--- /dev/null
+++ b/images/radicle-server/.gitignore
@@ -0,0 +1 @@
+/bin
diff --git a/images/radicle-server/Dockerfile b/images/radicle-server/Dockerfile
new file mode 100644
index 0000000..4e0e320
--- /dev/null
+++ b/images/radicle-server/Dockerfile
@@ -0,0 +1,16 @@
+FROM debian:stretch
+# The distribution must be the same one the binary is build with to
+# ensure binary compatibility. We use the `haskell` images on CI and
+# `fpco/stack-build` with when building with `stack build --docker`.
+
+RUN apt-get -qq update && \
+ apt-get -yqq install libpq5 && \
+ rm -rf /var/lib/apt/lists/*
+
+ADD ./ /
+
+# Executing the binary ensures that all linked libraries are present
+RUN radicle-server --help >/dev/null
+
+EXPOSE 8000
+CMD ["/bin/radicle-server"]
diff --git a/images/radicle-server/build.sh b/images/radicle-server/build.sh
new file mode 100755
index 0000000..cf4cf58
--- /dev/null
+++ b/images/radicle-server/build.sh
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+set -eo pipefail
+
+image_root=$(dirname $0)
+
+echo "Building radicle-server in container"
+stack build --docker
+
+bin_path=$(stack exec --docker -- which radicle-server)
+
+mkdir -p "$image_root/bin"
+cp -a "$bin_path" "$image_root/bin"
+
+docker build -t eu.gcr.io/opensourcecoin/radicle-server $image_root
diff --git a/images/radicle-server/ci-copy-bin.sh b/images/radicle-server/ci-copy-bin.sh
new file mode 100755
index 0000000..bd441cb
--- /dev/null
+++ b/images/radicle-server/ci-copy-bin.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+set -eo pipefail
+
+image_root=$(dirname $0)
+
+bin_path=$(stack exec -- which radicle-server)
+
+mkdir -p "$image_root/bin"
+cp -a "$bin_path" "$image_root/bin"
diff --git a/images/radicle-server/docker-compose.yaml b/images/radicle-server/docker-compose.yaml
new file mode 100644
index 0000000..7448b21
--- /dev/null
+++ b/images/radicle-server/docker-compose.yaml
@@ -0,0 +1,23 @@
+version: '3'
+
+services:
+ postgres:
+ image: postgres:11-alpine
+ ports:
+ - "15432:5432"
+ volumes:
+ - pg-data:/var/lib/postgresql/data
+ radicle-server:
+ image: eu.gcr.io/opensourcecoin/radicle-server
+ build: .
+ depends_on:
+ - postgres
+ command:
+ - radicle-server
+ - --host=postgres
+ - --db=postgres
+ ports:
+ - "8024:8000"
+
+volumes:
+ pg-data: {}
diff --git a/stack.yaml b/stack.yaml
index 53f1355..a3d5686 100644
--- a/stack.yaml
+++ b/stack.yaml
@@ -44,16 +44,15 @@ extra-deps:
- cborg-0.2.0.0
- acid-state-0.14.3
-image:
- containers:
- - base: "fpco/ubuntu-with-libgmp:14.04"
- name: "radicle/server"
- executables:
- - server
-
# Override default flag values for local packages and extra-deps
# flags: {}
+docker:
+ enable: false
+ # The default "host" does not work if the host version of stack is
+ # not statically linked, which is the case on Arch.
+ stack-exe: download
+
# Extra package databases containing global packages
# extra-package-dbs: []