From 48b047fd6104f0676ac150d36b6f33470562e850 Mon Sep 17 00:00:00 2001 From: Preston Van Loon Date: Sun, 22 Jul 2018 13:31:43 -0400 Subject: [PATCH] Add Docker Container Images for beacon-chain and client (#314) * Add docker container images for beacon-chain and client * Add docker section to README --- .travis.yml | 6 ++++++ README.md | 27 +++++++++++++++++++++++++++ WORKSPACE | 16 ++++++++++++++++ beacon-chain/BUILD.bazel | 19 +++++++++++++++++++ client/BUILD.bazel | 19 +++++++++++++++++++ 5 files changed, 87 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2df9c314a..359a7039f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,12 @@ matrix: install: true # Skip install go packages. script: + # Ensure everything builds + - | + bazel \ + --bazelrc=.travis-bazelrc \ + build \ + //... # Run all tests. - | bazel \ diff --git a/README.md b/README.md index e90acf8cf..bdd8231ce 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,33 @@ bazel run //client -- \ Omitting the `--actor` flag will launch a simple observer service attached to the sharding client that is able to listen to changes happening throughout the sharded Ethereum network on shard 0. +## Running via Docker + +To run the client within a docker container, use the `//client:image` target. + +```text +bazel run //client:image + +INFO: Build options have changed, discarding analysis cache. +INFO: Analysed target //client:image (306 packages loaded). +INFO: Found 1 target... +Target //client:image up-to-date: + bazel-bin/client/image-layer.tar +INFO: Elapsed time: 8.568s, Critical Path: 0.22s +INFO: 0 processes. +INFO: Build completed successfully, 1 total action +INFO: Build completed successfully, 1 total action +37fd88e7190b: Loading layer 22.42MB/22.42MB +Loaded image ID: sha256:89b233de1a026eddeeff010fa1ef596ce791cb3f26488150aac72a91b80734c1 +Tagging 89b233de1a026eddeeff010fa1ef596ce791cb3f26488150aac72a91b80734c1 as bazel/client:image +... +``` + +TODO: Add [container_push](https://github.com/bazelbuild/rules_docker/#container_push-1) +targets for the container images such that they can be pulled from GCR or +dockerhub. + + # Making Changes ## Rebuilding the Sharding Manager Contract Bindings diff --git a/WORKSPACE b/WORKSPACE index 4511d8c02..4dbd088cf 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -12,6 +12,13 @@ http_archive( sha256 = "bc653d3e058964a5a26dcad02b6c72d7d63e6bb88d94704990b908a1445b8758", ) +http_archive( + name = "io_bazel_rules_docker", + sha256 = "6dede2c65ce86289969b907f343a1382d33c14fbce5e30dd17bb59bb55bb6593", + strip_prefix = "rules_docker-0.4.0", + urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.4.0.tar.gz"], +) + load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains") go_rules_dependencies() @@ -22,6 +29,15 @@ load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") gazelle_dependencies() +load( + "@io_bazel_rules_docker//go:image.bzl", + _go_image_repos = "repositories", +) + +_go_image_repos() + +# External dependencies + go_repository( name = "com_github_ethereum_go_ethereum", importpath = "github.com/ethereum/go-ethereum", diff --git a/beacon-chain/BUILD.bazel b/beacon-chain/BUILD.bazel index 789b81529..730039023 100644 --- a/beacon-chain/BUILD.bazel +++ b/beacon-chain/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@io_bazel_rules_docker//go:image.bzl", "go_image") go_library( name = "go_default_library", @@ -16,6 +17,24 @@ go_library( ], ) +go_image( + name = "image", + srcs = ["main.go"], + goarch = "amd64", + goos = "linux", + importpath = "github.com/prysmaticlabs/prysm/beacon-chain", + static = "on", + deps = [ + "//beacon-chain/node:go_default_library", + "//beacon-chain/utils:go_default_library", + "//shared/cmd:go_default_library", + "//shared/debug:go_default_library", + "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_urfave_cli//:go_default_library", + "@com_github_x_cray_logrus_prefixed_formatter//:go_default_library", + ], +) + go_binary( name = "beacon-chain", embed = [":go_default_library"], diff --git a/client/BUILD.bazel b/client/BUILD.bazel index 6f375347a..3d6c62e30 100644 --- a/client/BUILD.bazel +++ b/client/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@io_bazel_rules_docker//go:image.bzl", "go_image") go_library( name = "go_default_library", @@ -16,6 +17,24 @@ go_library( ], ) +go_image( + name = "image", + srcs = ["main.go"], + goarch = "amd64", + goos = "linux", + importpath = "github.com/prysmaticlabs/prysm/client", + static = "on", + deps = [ + "//client/node:go_default_library", + "//client/utils:go_default_library", + "//shared/cmd:go_default_library", + "//shared/debug:go_default_library", + "@com_github_sirupsen_logrus//:go_default_library", + "@com_github_urfave_cli//:go_default_library", + "@com_github_x_cray_logrus_prefixed_formatter//:go_default_library", + ], +) + go_binary( name = "client", embed = [":go_default_library"],