Skip to content

Commit

Permalink
feat: Add Dockerfiles for armhf and arm64 (iotaledger#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuriel77 authored and IoTMOD committed Jan 16, 2020
1 parent 48ac733 commit 6edf211
Show file tree
Hide file tree
Showing 14 changed files with 283 additions and 119 deletions.
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
latest-export.gz.bin
.github
.git
Dockerfile
DOCKER.md
docker/
mainnetdb/
snapshot/
README.md
.dockerignore
docker-compose.yml
6 changes: 3 additions & 3 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ name: Build Docker
on:
push:
paths:
- "Dockerfile"
- "docker/Dockerfile"
- "docker-compose.yml"
pull_request:
paths:
- "Dockerfile"
- "docker/Dockerfile"
- "docker-compose.yml"

jobs:
Expand All @@ -18,7 +18,7 @@ jobs:
uses: actions/checkout@v1

- name: Build HORNET Docker image
run: docker build . --file Dockerfile --tag hornet:latest
run: docker build . --file docker/Dockerfile --tag hornet:latest

- name: Test HORNET Docker image
run: docker run --rm --name hornet hornet:latest --help 2>/dev/null | grep -q "help requested"
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ name: Release
on:
release:
types: [published]

jobs:
Release:
name: Release
runs-on: [ubuntu-latest]
container:
image: iotmod/goreleaser-cgo-cross-compiler:1.13.5-musl
volumes: [/repo]

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Docker login
env:
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ plugins/monitor/tanglemonitor

# dist packages
dist/

# Snapshot directory (for docker running in main path)
snapshot/
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dockers:
- "gohornet/hornet:{{ .Tag }}"
binaries:
- hornet
dockerfile: Dockerfile.goreleaser
dockerfile: docker/Dockerfile.goreleaser

# Archives
archives:
Expand Down
61 changes: 0 additions & 61 deletions DOCKER.md

This file was deleted.

43 changes: 0 additions & 43 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ Pull HORNET from [Docker Hub](https://hub.docker.com/r/gohornet/hornet)

**Build a Docker image**

- See [Docker](DOCKER.md)
- See [Docker](docker/DOCKER.md)
12 changes: 7 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ services:
hornet:
build:
context: .
dockerfile: Dockerfile
# For aarch64/arm64 use ARCH=arm64
# or for arm32 use ARCH=armhf
args:
- ARCH=amd64
# For aarch64/arm64 use Dockerfile.arm64
# or Dockerfile.armhf for arm32/armhf
dockerfile: docker/Dockerfile
image: hornet:latest
# Best performance via host network:
network_mode: host
Expand All @@ -17,6 +15,10 @@ services:
# - "15600:15600"
cap_drop:
- ALL
# Note: for local snapshots to work please
# read the DOCKER.md on how to mount a new
# path where latest-export.gz.bin should be
# placed in.
volumes:
- ./config.json:/app/config.json:ro
- ./neighbors.json:/app/neighbors.json
Expand Down
121 changes: 121 additions & 0 deletions docker/DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Hornet in Docker

*Table of contents*

<!--ts-->
* [Requirements](#requirements)
* [Quick Start](#quick-start)
* [Clone Repository](#clone-repository)
* [Prepare](#prepare)
* [Docker Compose](#docker-compose)
* [Build Image](#build-image)
* [Run](#run)
* [Local Snapshots](#local-snapshots)
* [Build Specific Version](#build-specific-version)
<!--te-->

## Requirements

1. A recent release of Docker enterprise or community edition.

2. git and curl

3. At least 1GB available RAM

## Quick Start

### Clone Repository
Clone the repository

```sh
git clone https://github.com/gohornet/hornet && cd hornet
```
The rest of the document assumes you are executing commands from the root directory of the repository.

### Prepare

i. Download the DB file
```sh
curl -LO https://dbfiles.iota.org/mainnet/hornet/latest-export.gz.bin
```

ii. Edit the `config.json` for alternative ports if needed.

iii. Edit `neighbors.json` to your neighbors addresses.

iv. The docker image runs under user with uid 39999. To make sure no permission issues, create the directory for the database, e.g.:
```sh
mkdir mainnetdb && chown 39999:39999 mainnetdb
```
### Docker Compose

Note: Follow this step only if you want to run Hornet via docker-compose.

If you are using an architecture other than amd64/x86_64 edit the `docker-compose.yml` file and set the correct architecture where noted.

The following command will build the image and run Hornet:
```sh
docker-compose up
```
CTRL-c to stop.

Add `-d` to run detached, and to stop:

```sh
docker-compose down -t 1200
```

### Build Image
If not running via docker-compose, build the image manually:

```sh
docker build -f docker/Dockerfile -t hornet:latest .
```
Or pull it from dockerhub (only available for amd64/x86_64):

```sh
docker pull gohornet/hornet:latest && docker tag gohornet/hornet:latest hornet:latest
```

Note: for architectures other than amd64/x86_64 pass the corresponding Dockerfile, e.g.:
```sh
docker build -f docker/Dockerfile.arm64 -t hornet:latest .
```


### Run

Best is to run on host network for better performance (otherwise you are going to have to publish ports, that is done via iptables NAT and is slower)
```sh
docker run --rm -v $(pwd)/config.json:/app/config.json:ro -v $(pwd)/latest-export.gz.bin:/app/latest-export.gz.bin:ro -v $(pwd)/mainnetdb:/app/mainnetdb --name hornet --net=host hornet:latest
```
Use CTRL-c to gracefully end the process.

## Local Snapshots

Version `0.3.0` of Hornet introduced the local snapshots feature. To make sure it works well in Docker, follow these steps:

Before you begin, make sure hornet is stopped.

i. Create and download the latest-export to a separate directory:
```sh
mkdir -p snapshot\
&& curl -L -o snapshot/latest-export.gz.bin https://dbfiles.iota.org/mainnet/hornet/latest-export.gz.bin\
&& chown 39999:39999 snapshot -R
```

ii. Edit `config.json` and set the correct path. This can be done using `sed`:
```sh
sed -i 's#"path": "latest-export.gz.bin"#"path": "snapshot/latest-export.gz.bin"#' config.json
```

iii. To run docker you should mount the new `snapshot` directory with read-write mode. This allows Hornet to update the `latest-export.gz.bin` file:
```sh
docker run --rm -v $(pwd)/config.json:/app/config.json:ro -v $(pwd)/snapshot:/app/snapshot:rw -v $(pwd)/mainnetdb:/app/mainnetdb --name hornet --net=host hornet:latest
```

## Build Specific Version
By default the Dockerfile builds the image using Hornet's latest version. To build an image with a specific version you can pass it via the build argument `TAG`, e.g.:
```sh
docker build -f docker/Dockerfile -t hornet:v0.3.0 --build-arg TAG=v0.3.0 .
```
47 changes: 47 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
FROM alpine:latest

ARG REPO="gohornet/hornet"
ARG TAG=latest
ARG ARCH=x86_64
ARG OS=Linux

LABEL org.label-schema.description="HORNET - The IOTA community node"
LABEL org.label-schema.name="gohornet/hornet"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.vcs-url="https://github.com/gohornet/hornet"
LABEL org.label-schema.usage="https://github.com/gohornet/hornet/blob/master/DOCKER.md"

WORKDIR /app

RUN apk --no-cache add curl jq tini tar\
&& if [ "$TAG" = "latest" ];\
then\
HORNET_TAG=$(curl --retry 3 -f -s https://api.github.com/repos/${REPO}/releases/latest | jq -r .tag_name | tr -d 'v');\
else\
HORNET_TAG="${TAG//v}";\
fi\
&& echo "Downloading from https://github.com/${REPO}/releases/download/v${HORNET_TAG}/HORNET-${HORNET_TAG}_${OS}_${ARCH}.tar.gz ..."\
&& curl -f -L --retry 3 "https://github.com/${REPO}/releases/download/v${HORNET_TAG}/HORNET-${HORNET_TAG}_${OS}_${ARCH}.tar.gz" -o /tmp/hornet.tgz\
&& tar --wildcards --strip-components=1 -xf /tmp/hornet.tgz -C /app/ */hornet */config.json */neighbors.json\
&& if [ "$ARCH" = "x86_64" ];\
then\
curl -f -L --retry 3 -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub;\
curl -f -L --retry 3 -o glibc-2.30-r0.apk https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk;\
apk add glibc-2.30-r0.apk;\
rm glibc-2.30-r0.apk;\
fi\
&& addgroup --gid 39999 hornet\
&& adduser -h /app -s /bin/sh -G hornet -u 39999 -D hornet\
&& chmod +x /app/hornet\
&& chown hornet:hornet -R /app\
&& rm /tmp/hornet.tgz\
&& apk del jq curl

# Not exposing ports, as it might be more efficient to run this on host network because of performance gain.
# | Host mode networking can be useful to optimize performance, and in situations where a container needs
# | to handle a large range of ports, as it does not require network address translation (NAT), and no
# | “userland-proxy” is created for each port.
# Source: https://docs.docker.com/network/host/

USER hornet
ENTRYPOINT ["/sbin/tini", "--", "/app/hornet"]
Loading

0 comments on commit 6edf211

Please sign in to comment.