Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
greenaddress committed Nov 17, 2018
0 parents commit 2d7afb1
Show file tree
Hide file tree
Showing 164 changed files with 13,824 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .ackrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--ignore-dir=dist
--ignore-dir=www/img
--ignore-dir=www/font
--ignore-file=is:bootstrap.min.css
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": ["env"]
, "plugins": [
"transform-object-rest-spread"
]
}
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.gitignore
README.md
Dockerfile
.gitlab-ci.yml
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
dist
terraform/.terraform
terraform/.terraform/environment
terraform/*.tfstate.backup
terraform/*.tfstate
123 changes: 123 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
variables:
CI_DISPOSABLE_ENVIRONMENT: "true"
CLOUD_SDK_VERSION: "218.0.0"
DOCKER_DRIVER: overlay2

image: blockstream/gcloud-docker@sha256:86c3b471e6aa9790007fbd7dff459737d81947277ac612d2c18d2cf3aee62d19
stages:
- build
- deploy

before_script:
- TMPF=$(mktemp) || exit 1
- echo $GCLOUD_KEY > $TMPF
- export GOOGLE_APPLICATION_CREDENTIALS=$TMPF
- gcloud auth activate-service-account --key-file=$TMPF
- gcloud auth list
- gcloud --version

test_docker_build_image:
image: docker@sha256:f7211e1779c82e3a50d0d6f165e83f3e2be217a234b0181d5e8bee411d8fcc5f
stage: build
before_script:
- echo "Disabling before script"
except:
- tags
- master
script:
- docker build --build-arg CUSTOM_HTML='<!-- '"$CI_COMMIT_SHA"'-->' -t esplora .
- docker rmi esplora

build:
stage: build
only:
- /^bitcoin_mainnet.*/
- /^bitcoin_testnet.*/
- /^liquid_mainnet.*/
- master@greenaddress/esplora
script:
- gcloud container images list-tags gcr.io/green-address-explorer/explorer-deploy | grep -q $CI_COMMIT_SHA || (
docker build
--squash
--build-arg CUSTOM_HTML='<!-- '"$CI_COMMIT_SHA"' -->'
--cache-from gcr.io/green-address-explorer/explorer-deploy:latest
-t gcr.io/green-address-explorer/explorer-deploy:$CI_COMMIT_SHA
-t gcr.io/green-address-explorer/explorer-deploy:latest .
&& docker push gcr.io/green-address-explorer/explorer-deploy:$CI_COMMIT_SHA)

deploy:
stage: deploy
image:
name: blockstream/gcloud-terraform@sha256:40e23b0e89a66ae24e1e8ee9770b9bab3b71ebae50615c8ff5023ff3d5392344
entrypoint: [""]
only:
- master@greenaddress/esplora
script:
- (cd terraform && terraform init -input=false)
- (cd terraform && terraform workspace select main)
- (cd terraform && terraform apply
-var "prometheus_allowed_source_ip=$PROMETHEUS_ALLOWED_SOURCE_IP"
-var "machine_type=$GRAF_PROM_MACHINE_TYPE"
-var "hosts=$HOSTS"
-var "hosts_onion=$HOSTS_ONION"
-var "cluster_size=$NODE_CLUSTER_SIZE"
-var "instance_type=$NODE_INSTANCE_TYPE"
-var "regions=$REGIONS"
-var "zones=$ZONES"
-var "ssl_certs=$SSL_CERTS"
-var "opsgenie_api_key=$OPSGENIE_API_KEY"
-input=false -auto-approve)

deploy_bitcoin_mainnet:
stage: deploy
image:
name: blockstream/gcloud-terraform@sha256:40e23b0e89a66ae24e1e8ee9770b9bab3b71ebae50615c8ff5023ff3d5392344
entrypoint: [""]
only:
- /^bitcoin_mainnet.*/
script:
- (cd terraform && terraform init -input=false)
- (cd terraform && terraform workspace select bitcoin-mainnet)
- (cd terraform && terraform apply
-var "docker_tag_explorer=gcr.io/green-address-explorer/explorer-deploy:$CI_COMMIT_SHA"
-var "cluster_size=$NODE_CLUSTER_SIZE"
-var "instance_type=$NODE_INSTANCE_TYPE"
-var "regions=$REGIONS"
-var "zones=$ZONES"
-input=false -auto-approve)

deploy_bitcoin_testnet:
stage: deploy
image:
name: blockstream/gcloud-terraform@sha256:40e23b0e89a66ae24e1e8ee9770b9bab3b71ebae50615c8ff5023ff3d5392344
entrypoint: [""]
only:
- /^bitcoin_testnet.*/
script:
- (cd terraform && terraform init -input=false)
- (cd terraform && terraform workspace select bitcoin-testnet)
- (cd terraform && terraform apply
-var "docker_tag_explorer=gcr.io/green-address-explorer/explorer-deploy:$CI_COMMIT_SHA"
-var "cluster_size=$NODE_CLUSTER_SIZE"
-var "instance_type=$NODE_INSTANCE_TYPE"
-var "regions=$REGIONS"
-var "zones=$ZONES"
-input=false -auto-approve)

deploy_liquid_mainnet:
stage: deploy
image:
name: blockstream/gcloud-terraform@sha256:40e23b0e89a66ae24e1e8ee9770b9bab3b71ebae50615c8ff5023ff3d5392344
entrypoint: [""]
only:
- /^liquid_mainnet.*/
script:
- (cd terraform && terraform init -input=false)
- (cd terraform && terraform workspace select liquid-mainnet)
- (cd terraform && terraform apply
-var "docker_tag_explorer=gcr.io/green-address-explorer/explorer-deploy:$CI_COMMIT_SHA"
-var "cluster_size=$NODE_CLUSTER_SIZE"
-var "instance_type=$NODE_INSTANCE_TYPE"
-var "regions=$REGIONS"
-var "zones=$ZONES"
-input=false -auto-approve)
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM blockstream/esplora-base@sha256:b9c388dd7e99bb808fce981fc788a1915976a4236881b95001847b373514e1d5 AS build

FROM debian:stretch@sha256:802706fa62e75c96fff96ada0e8ca11f570895ae2e9ba4a9d409981750ca544c

COPY --from=build /srv/explorer /srv/explorer
COPY --from=build /root/.nvm /root/.nvm

RUN sed -i 's/deb.debian.org/httpredir.debian.org/g' /etc/apt/sources.list \
&& apt-get -yqq update \
&& apt-get -yqq upgrade \
&& apt-get -yqq install nginx supervisor tor git curl

RUN mkdir /tmp/explorer \
&& mkdir -p /srv/explorer/static

COPY ./ /tmp/explorer

ARG CUSTOM_HTML

WORKDIR /tmp/explorer

SHELL ["/bin/bash", "-c"]

# required to run some scripts as root (needed for docker)
RUN source /root/.nvm/nvm.sh \
&& npm config set unsafe-perm true \
&& npm run dist:bitcoin-testnet \
&& npm run dist:bitcoin-mainnet \
&& npm run dist:liquid-mainnet \
&& mv dist/* /srv/explorer/static

# configuration
RUN cp /tmp/explorer/contrib/*.conf.in /tmp/explorer/contrib/*torrc /tmp/explorer/run.sh /tmp/explorer/cli.sh.in /srv/explorer/

# cleanup
RUN apt-get --auto-remove remove -yqq --purge manpages git curl \
&& apt-get clean \
&& apt-get autoclean \
&& rm -rf /usr/share/doc* /usr/share/man /usr/share/postgresql/*/man /var/lib/apt/lists/* /var/cache/* /tmp/* /root/.cache /*.deb /root/.nvm /root/.cargo

WORKDIR /srv/explorer
49 changes: 49 additions & 0 deletions Dockerfile.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM debian:stretch@sha256:802706fa62e75c96fff96ada0e8ca11f570895ae2e9ba4a9d409981750ca544c

SHELL ["/bin/bash", "-c"]

RUN mkdir -p /srv/explorer \
&& sed -i 's/deb.debian.org/httpredir.debian.org/g' /etc/apt/sources.list \
&& apt-get -yqq update \
&& apt-get -yqq upgrade \
&& apt-get -yqq install clang cmake nginx supervisor curl git tor

RUN git clone --quiet --depth 1 --single-branch --branch v0.33.11 https://github.com/creationix/nvm.git /root/.nvm \
&& rm -rf /root/.nvm/.git \
&& source /root/.nvm/nvm.sh \
&& nvm install v8.11.4

ENV SHA256SUM_BITCOINCORE=9d6b472dc2aceedb1a974b93a3003a81b7e0265963bd2aa0acdcb17598215a4f
RUN curl -sL -o bitcoin.tar.gz https://bitcoincore.org/bin/bitcoin-core-0.17.0/bitcoin-0.17.0-x86_64-linux-gnu.tar.gz \
&& echo "${SHA256SUM_BITCOINCORE} bitcoin.tar.gz" | sha256sum --check \
&& tar xzf bitcoin.tar.gz -C /srv/explorer \
&& ln -s /srv/explorer/bitcoin-0.17.0 /srv/explorer/bitcoin \
&& rm bitcoin.tar.gz

ENV SHA256SUM_LIQUID=ea2836aa267b32b29e890acdd5e724b4be225c34891fd26426ce741c12c1e166
RUN curl -sL -o liquid.tar.gz https://github.com/Blockstream/liquid/releases/download/liquid.3.14.1.21/liquid-3.14.1.21-x86_64-linux-gnu.tar.gz \
&& echo "${SHA256SUM_LIQUID} liquid.tar.gz" | sha256sum --check \
&& tar xzf liquid.tar.gz -C /srv/explorer \
&& ln -s /srv/explorer/liquid-3.14.1.21 /srv/explorer/liquid \
&& rm liquid.tar.gz

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y \
&& source /root/.cargo/env \
&& mkdir -p /srv/explorer/electrs{,_liquid} \
&& git clone --no-checkout https://github.com/greenaddress/electrs.git \
&& cd electrs \
&& git checkout 32239bd7f56e0e5076f7cf7f546dc748026f4569 \
&& cargo build --release \
&& cargo install --root /srv/explorer/electrs_bitcoin \
&& git checkout --force e82c904f2662371319eab16d4ddbcf5e35cbf93a \
&& cargo build --release \
&& cargo install --root /srv/explorer/electrs_liquid \
&& cd .. \
&& rm -fr /root/.cargo electrs \
&& strip /srv/explorer/electrs_*/bin/electrs

# cleanup
RUN apt-get --auto-remove remove -yqq --purge clang cmake manpages curl git \
&& apt-get clean \
&& apt-get autoclean \
&& rm -rf /usr/share/doc* /usr/share/man /usr/share/postgresql/*/man /var/lib/apt/lists/* /var/cache/* /tmp/* /root/.cache /*.deb /root/.cargo
22 changes: 22 additions & 0 deletions Dockerfile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM docker@sha256:f7211e1779c82e3a50d0d6f165e83f3e2be217a234b0181d5e8bee411d8fcc5f

ENV CLOUD_SDK_VERSION="224.0.0"
ENV PATH=/opt/google-cloud-sdk/bin:$PATH

WORKDIR /opt

RUN wget https://github.com/DeviaVir/terraform-provider-customconfig/releases/download/v0.0.1/terraform-provider-customconfig_0.0.1_linux_amd64.tgz \
&& tar xzf terraform-provider-customconfig_0.0.1_linux_amd64.tgz \
&& mkdir -p $HOME/.terraform.d/plugins/ \
&& mv terraform-provider-customconfig_v0.0.1 $HOME/.terraform.d/plugins/

RUN apk --no-cache add curl python py-crcmod bash libc6-compat openssh-client git gnupg \
&& curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& ln -s /lib /lib64

RUN /opt/google-cloud-sdk/bin/gcloud config set core/disable_usage_reporting true \
&& /opt/google-cloud-sdk/bin/gcloud config set component_manager/disable_update_check true \
&& /opt/google-cloud-sdk/bin/gcloud config set metrics/environment github_docker_image \
&& /opt/google-cloud-sdk/bin/gcloud auth configure-docker
22 changes: 22 additions & 0 deletions Dockerfile.terraform
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM hashicorp/terraform@sha256:3d5eb7a88d94f5216658b804acd70597e0315b8839a099a3d33baa45494bca65

ENV CLOUD_SDK_VERSION="224.0.0"
ENV PATH=/opt/google-cloud-sdk/bin:$PATH

WORKDIR /opt

RUN wget https://github.com/DeviaVir/terraform-provider-customconfig/releases/download/v0.0.1/terraform-provider-customconfig_0.0.1_linux_amd64.tgz \
&& tar xzf terraform-provider-customconfig_0.0.1_linux_amd64.tgz \
&& mkdir -p $HOME/.terraform.d/plugins/ \
&& mv terraform-provider-customconfig_v0.0.1 $HOME/.terraform.d/plugins/

RUN apk --no-cache add curl python py-crcmod bash libc6-compat openssh-client git gnupg \
&& curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& tar xzf google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& rm google-cloud-sdk-${CLOUD_SDK_VERSION}-linux-x86_64.tar.gz \
&& ln -s /lib /lib64

RUN /opt/google-cloud-sdk/bin/gcloud config set core/disable_usage_reporting true \
&& /opt/google-cloud-sdk/bin/gcloud config set component_manager/disable_update_check true \
&& /opt/google-cloud-sdk/bin/gcloud config set metrics/environment github_docker_image \
&& /opt/google-cloud-sdk/bin/gcloud auth configure-docker
5 changes: 5 additions & 0 deletions HACKS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- @cycle/history had to be patched (via patch-package) to properly handle <base href>

- search form submissions were not properly caught by cyclejs's dom driver, had to be
worked around with a hairy hack.

57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# How to build the Docker image

```
docker build -t esplora .
```

# How to run the explorer for Bitcoin mainnet

```
docker run --port 8080:80 \
--volume $PWD/data_bitcoin_mainnet:/data \
--rm -i -t esplora \
bash -c "/srv/explorer/run.sh bitcoin-mainnet explorer"
```

# How to run the explorer for Liquid mainnet

```
docker run --port 8082:80 \
--volume $PWD/data_liquid_mainnet:/data \
--rm -i -t esplora \
bash -c "/srv/explorer/run.sh liquid-mainnet explorer"
```

# How to run the explorer for Bitcoin testnet3

```
docker run --port 8084:80 \
--volume $PWD/data_bitcoin_testnet:/data \
--rm -i -t esplora \
bash -c "/srv/explorer/run.sh bitcoin-testnet explorer"
```


# Build new esplora-base

```
docker build -t blockstream/esplora-base:latest -f Dockerfile.deps .
docker push blockstream/esplora-base:latest
docker inspect --format='{{index .RepoDigests 0}}' blockstream/esplora-base
```

# Build new gcloud-docker

```
docker build --squash -t blockstream/gcloud-docker:latest -f Dockerfile.docker .
docker push blockstream/gcloud-docker:latest
docker inspect --format='{{index .RepoDigests 0}}' blockstream/gcloud-docker
```

# Build new gcloud-terraform

```
docker build --squash -t blockstream/gcloud-terraform:latest -f Dockerfile.terraform .
docker push blockstream/gcloud-terraform:latest
docker inspect --format='{{index .RepoDigests 0}}' blockstream/gcloud-terraform
```
31 changes: 31 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -xeo pipefail
shopt -s extglob

: ${DEST:=dist}
: ${NODE_ENV:=production}

export NODE_ENV

mkdir -p $DEST
rm -rf $DEST/*

[[ -d node_modules ]] || npm install
(cd client && [[ -d node_modules ]] || npm install)

# Static assets
cp -rL www/* $DEST/

# Index HTML
pug index.pug -o $DEST

# RTLify CSS
cat www/style.css | node -p "require('cssjanus').transform(fs.readFileSync('/dev/stdin').toString(), false, true)" > $DEST/style-rtl.css

# Browserify bundle
(cd client && browserify -p bundle-collapser/plugin app.js \
| ( [[ "$NODE_ENV" != "development" ]] && uglifyjs -cm || cat ) ) \
> $DEST/app.js

# Pre-render notfound.html
babel-node render-view.js '{"view":"error","error":"Page Not Found"}' > $DEST/notfound.html
4 changes: 4 additions & 0 deletions cli.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -eo pipefail

/srv/explorer/{DAEMON}/bin/{DAEMON}-cli -conf=/data/.{DAEMON}.conf "$@"
7 changes: 7 additions & 0 deletions client/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [ "env" ]
, "plugins": [
"transform-object-rest-spread"
, ["transform-react-jsx", {"pragma": "Snabbdom.createElement"}]
]
}
Loading

0 comments on commit 2d7afb1

Please sign in to comment.