hepsw / docks

a set of Dockerfiles defining docker containers for HEP software and appliances.
BSD 3-Clause "New" or "Revised" License
17 stars 13 forks source link

travis: add a travis-ci entry point for uploading to hepsw docker hub #26

Open kreczko opened 7 years ago

kreczko commented 7 years ago

This issue comes in two steps. Firstly, it is important to change the current travis setup to a build-matrix, e.g. add

env:
  - IMAGE=cvmfs-base BUILD=build UPLOAD=upload
  - IMAGE=cvmfs-base-cc7 BUILD=build-cc7 UPLOAD=upload-cc7
  - ...

script:
  - cd $IMAGE
  - make $BUILD

This allows fine-grained testing on a per-image basis.

The second part is to define what will happen after a successful build:

after_success:
 - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
 - cd $IMAGE
 - make $UPLOAD

The mentioned docker details for https://hub.docker.com/u/hepsw/ need to be added in an encrypted form as shown in https://sebest.github.io/post/using-travis-ci-to-build-docker-images/. The downside is that the upload will not work for PRs from forks but only for tagged or master builds (i.e. after the merge).

Travis also recommends to create two sets of scripts as secrets won't be available to PRs from forks:

after_success:
   - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./travis/run_on_pull_requests; fi'
   - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./travis/run_on_non_pull_requests; fi'

This means all the above would come together as

sudo: required

services:
  - docker

env:
  global:
    - secure: "UkF2CHX0lUZ...VI/LE=" # DOCKER_EMAIL
    - secure: "Z3fdBNPt5hR...VI/LE=" # DOCKER_USER
    - secure: "F4XbD6WybHC...VI/LE=" # DOCKER_PASS
  matrix:
    - IMAGE=cvmfs-base BUILD=build UPLOAD=upload
    - IMAGE=cvmfs-base-cc7 BUILD=build-cc7 UPLOAD=upload-cc7
    - ...

script:
  - cd $IMAGE
  - make $BUILD

after_success:
   - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./travis/no_upload; fi'
   - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./travis/upload_stuff; fi'

with ./travis/no_upload

#!/usr/bin/env bash
echo "No upload"

and ./travis/upload_stuff

#!/usr/bin/env bash
echo "Pushing $IMAGE to docker hub"
docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
cd $IMAGE
make $UPLOAD