From 23b4016923316a914800d914ad55328ab8749015 Mon Sep 17 00:00:00 2001 From: Romain Date: Sat, 21 Jul 2018 01:07:54 +0200 Subject: [PATCH] chore(build): automatically build and publish the Docker image with Travis CI Fixes #114. --- .dockerignore | 3 ++- .github/CONTRIBUTING.md | 2 +- .travis.yml | 35 ++++++++++++++++++++++++++++++----- Dockerfile.release | 33 +++++++++++++++++++++++++++++++++ Dockerfile => Dockerfile.test | 2 +- scripts/cibuild | 20 -------------------- 6 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 Dockerfile.release rename Dockerfile => Dockerfile.test (95%) delete mode 100755 scripts/cibuild diff --git a/.dockerignore b/.dockerignore index 292627a..c143741 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ +coverage node_modules -test-snapshot/output-actual +tmp diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 02785a7..395df9d 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -16,7 +16,7 @@ npm test Note: due to the nature of `thumbsup`, some tests require a working runtime environment including `exiftool`, `graphicsmagick` and `ffmpeg`. You can run the entire test suite inside Docker using: ```bash -docker build . +docker build -f Dockerfile.test . ``` ## Manual tests diff --git a/.travis.yml b/.travis.yml index d6e8326..b43b7bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,42 @@ -# Run the whole build inside Docker +# Build steps need access to the Docker agent sudo: required services: - docker jobs: include: - - stage: build - script: docker build . - - stage: npm release - script: echo "Deploying to npm ..." + + # Run all the tests inside Docker + + - stage: Test + script: docker build -f Dockerfile.test . + + + # If this is a tagged commit, publish the package to npm + + - stage: Release npm + script: echo "Deploying to npm" deploy: provider: npm email: asyncadventures@gmail.com api_key: $NPM_TOKEN on: tags: true + condition: $TRAVIS_TAG =~ ^\d+\.\d+\.\d+$ + + # If this is a tagged commit, publish a new Docker image + + - stage: Release Docker + script: echo "Deploying to DockerHub" + deploy: + provider: script + script: + - DOCKER_IMAGE="thumbsupgallery/thumbsup" + - docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}" + - docker build -f Dockerfile.release -t "${DOCKER_IMAGE}:TRAVIS_TAG" --build-arg "PACKAGE_VERSION=${TRAVIS_TAG}" . + - docker tag "${DOCKER_IMAGE}:${TRAVIS_TAG}" "${DOCKER_IMAGE}:latest" + - docker push "${DOCKER_IMAGE}:${TRAVIS_TAG}" + - docker push "${DOCKER_IMAGE}:latest" + on: + tags: true + condition: $TRAVIS_TAG =~ ^\d+\.\d+\.\d+$ diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..10309b9 --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,33 @@ +# ------------------------------------------------ +# Builder image +# ------------------------------------------------ + +FROM thumbsupgallery/build:alpine as build + +# Install thumbsup locally +WORKDIR /thumbsup +ARG PACKAGE_VERSION +RUN if [ -z "${PACKAGE_VERSION}" ]; then \ + echo "Please specify --build-arg PACKAGE_VERSION=<2.4.1>"; \ + exit 1; \ + fi; +RUN echo "Installing thumbsup@${PACKAGE_VERSION}" +RUN npm install thumbsup@${PACKAGE_VERSION} + +# ------------------------------------------------ +# Runtime image +# ------------------------------------------------ + +FROM thumbsupgallery/runtime:alpine + +# Use tini as an init process +# to ensure all child processes (ffmpeg...) are always terminated properly +RUN apk add --update tini +ENTRYPOINT ["tini", "-g", "--"] + +# Copy the thumbsup files to the new image +COPY --from=build /thumbsup /thumbsup +RUN ln -s /thumbsup/node_modules/.bin/thumbsup /usr/local/bin/thumbsup + +# Default command, should be overridden during +CMD ["thumbsup"] diff --git a/Dockerfile b/Dockerfile.test similarity index 95% rename from Dockerfile rename to Dockerfile.test index bc143bd..f55efe6 100644 --- a/Dockerfile +++ b/Dockerfile.test @@ -15,4 +15,4 @@ RUN npm install COPY --chown=tester . /app # Run the tests -RUN scripts/cibuild +RUN npm test diff --git a/scripts/cibuild b/scripts/cibuild deleted file mode 100755 index ed4ffeb..0000000 --- a/scripts/cibuild +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Fail the build on any error -set -eou pipefail - -trap failure ERR -function failure { - echo "" - echo "==================================" - echo " ✘ Build failed" - echo "==================================" -} - -echo "Run unit tests" -npm test - -echo "" -echo "==================================" -echo " ✔ Build successful" -echo "=================================="