Skip to content

Commit

Permalink
fix(docker): minimal docker images (#942)
Browse files Browse the repository at this point in the history
* alpine image and simpler circleci build

* include rsync

* run in correct container

* more steps to workflow

* run npm install with sudo

* git sha tag for now

* find the built image

* persist built image between workflows

* conditional tagging

* fix tag

* no need for additional scripts

* remove get logs script

* remove git from final binary

* clean up config and get reports and logs from containers

* export the env var

* hard coded container name

* fix syntax error on docker cp

* fix stupid typo

* fix(ci): build docker on tag release

* docs(badge): adds circleci build status badge
  • Loading branch information
WesleyCharlesBlake authored Mar 12, 2019
1 parent fb470a9 commit 9e51464
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 101 deletions.
119 changes: 119 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
version: 2

defaults: &defaults
environment:
REPO_NAME: poetapp/node
IMAGE_NAME: project_poet-node
DOCKER_COMPOSE_VERSION: 1.23.2
machine: true

jobs:
build:
<<: *defaults
steps:
- checkout
- run:
name: Install Docker Compose
command: |
curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
chmod +x ~/docker-compose
sudo mv ~/docker-compose /usr/local/bin/docker-compose
- run: docker-compose up -d
- run: docker-compose exec poet-node npm run lint
- run: docker-compose exec poet-node npm run coverage
- run:
name: Get logs
command: |
services="mongo rabbit ipfs bitcoind-1 bitcoind-2 k6 poet-node poet-node-blockchain-writer"
mkdir /tmp/logs
for i in $services
do
docker-compose logs $i > /tmp/logs/$i.log
done
when: on_fail
- run:
name: Get coverage report
command: |
mkdir -p /tmp/test-results
docker cp project_poet-node_1:/usr/src/app/.coverage /tmp/test-results
- run:
name: Archive Docker image
command: docker save -o image.tar ${IMAGE_NAME}
- persist_to_workspace:
root: .
paths:
- ./image.tar
- store_artifacts:
path: /tmp/logs
- store_artifacts:
path: /tmp/.coverage
- store_test_results:
path: /tmp/.coverage

git-tag-docker:
<<: *defaults
steps:
- checkout
- run:
name: Build docker image for git release
command: docker build -t "${REPO_NAME}":"${CIRCLE_TAG}" -t "${REPO_NAME}":"latest" .
- run:
name: Tag and Push Docker image
command: |
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
docker push "${REPO_NAME}"
semantic-release:
docker:
- image: circleci/node:8
steps:
- checkout
- run: sudo npm install -g semantic-release@15
- run: npx semantic-release

push:
<<: *defaults
working_directory: /tmp/workspace
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: Load archived Docker image
command: docker load -i image.tar
- run:
name: Tag and Push Docker image
command: |
TAG="v-$(echo $CIRCLE_SHA1 | cut -c 1-6)-beta"
docker tag "${IMAGE_NAME}" "${REPO_NAME}":"${TAG}"
docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"
docker push "${REPO_NAME}"
workflows:
version: 2
build_and_test:
jobs:
- build
- semantic-release:
context: docker
requires:
- build
filters:
branches:
only: master
- git-tag-docker:
context: docker
filters:
# ignore any commit on any branch by default
branches:
ignore: /.*/
# only act on version tags
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
- push:
context: docker
requires:
- build
filters:
branches:
only: master

49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

34 changes: 18 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
FROM node:10.14.2
FROM node:10.14.2-alpine as builder

RUN apt-get update && apt-get install -y rsync \
netcat \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*

RUN echo 'PS1="\u@${POET_SERVICE:-noService}:\w# "' >> ~/.bashrc
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package*.json /tmp/
RUN cd /tmp && npm ci
RUN mkdir -p /usr/src/app/ && cp -a /tmp/node_modules /usr/src/app/
COPY package*.json /usr/src/app/
COPY . /usr/src/app/

WORKDIR /usr/src/app
ADD . /usr/src/app/
RUN apk add --no-cache --virtual .gyp python make git g++ libtool autoconf automake rsync \
&& npm ci

RUN npm run build

COPY Docker/tools/wait-for-it.sh /
RUN chmod +x /wait-for-it.sh
FROM node:10.14.2-alpine as app

RUN rm -rf /var/lib/apt/lists/* \
/var/cache/apk/* \
/usr/share/man \
/tmp/*

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

CMD [ "npm", "start" ]
COPY --from=builder /usr/src/app .
CMD [ "npm", "start" ]
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Po.et Node

[![Build Status](https://travis-ci.org/poetapp/node.svg?branch=master)](https://travis-ci.org/poetapp/node)
[![CircleCI](https://circleci.com/gh/poetapp/node/tree/master.svg?style=svg)](https://circleci.com/gh/poetapp/node/tree/master)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![Docker Automated build](https://img.shields.io/docker/automated/poetapp/node.svg?style=flat)](https://hub.docker.com/r/poetapp/node/)
Expand All @@ -12,16 +12,24 @@ It's built on top of the [Bitcoin](https://github.com/bitcoin/bitcoin) blockchai

## Index

- [How to Run the Po.et Node](#how-to-run-the-poet-node)
- [The Po.et Node](#the-poet-node)
- [Index](#index)
- [How to Run the Po.et Node](#how-to-run-the-poet-node)
- [Dependencies](#dependencies)
- [Configuration](#configuration)
- [API](#api)
- [Building Claims](#building-claims)
- [Contributing](#contributing)
- [API](#api)
- [`GET /works?issuer=xxx&limit=x&offset=x`](#get-worksissuerxxxlimitxoffsetx)
- [`GET /works/:id`](#get-worksid)
- [`POST /works`](#post-works)
- [`POST /files`](#post-files)
- [Building Claims](#building-claims)
- [Verifying the Claim is on Bitcoin's Blockchain](#verifying-the-claim-is-on-bitcoins-blockchain)
- [Po.et JS](#poet-js)
- [Contributing](#contributing)
- [Compiling](#compiling)
- [Tests](#tests)
- [Coverage](#coverage)
- [Branches and Pull Requests](#branches-and-pull-requests)
- [Security](#security)

## How to Run the Po.et Node

Expand Down
22 changes: 0 additions & 22 deletions scripts/docker-build.sh

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/docker-push.sh

This file was deleted.

10 changes: 10 additions & 0 deletions scripts/get-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
services="bitcoind-1 consul frost-api ipfs mongo poet-node rabbit redis vault"

mkdir /tmp/logs

for i in $services
do
docker-compose logs $i > /tmp/logs/$i.log
done

0 comments on commit 9e51464

Please sign in to comment.