-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docker): minimal docker images (#942)
* 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
1 parent
fb470a9
commit 9e51464
Showing
7 changed files
with
161 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|