|
| 1 | +language: bash |
| 2 | + |
| 3 | +services: |
| 4 | + - docker |
| 5 | +env: |
| 6 | + global: |
| 7 | + - NAME="osixia/roundcube" |
| 8 | + - VERSION="${TRAVIS_BRANCH}-dev" |
| 9 | + matrix: |
| 10 | + - TARGET_ARCH=amd64 QEMU_ARCH=x86_64 |
| 11 | + - TARGET_ARCH=arm32v7 QEMU_ARCH=arm |
| 12 | + - TARGET_ARCH=arm64v8 QEMU_ARCH=aarch64 |
| 13 | + |
| 14 | +addons: |
| 15 | + apt: |
| 16 | + # The docker manifest command was added in docker-ee version 18.x |
| 17 | + # So update our current installation and we also have to enable the experimental features. |
| 18 | + sources: |
| 19 | + - sourceline: "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
| 20 | + key_url: "https://download.docker.com/linux/ubuntu/gpg" |
| 21 | + packages: |
| 22 | + - docker-ce |
| 23 | + |
| 24 | +before_install: |
| 25 | + - docker --version |
| 26 | + - mkdir $HOME/.docker |
| 27 | + - 'echo "{" > $HOME/.docker/config.json' |
| 28 | + - 'echo " \"experimental\": \"enabled\"" >> $HOME/.docker/config.json' |
| 29 | + - 'echo "}" >> $HOME/.docker/config.json' |
| 30 | + - sudo service docker restart |
| 31 | + |
| 32 | +install: |
| 33 | + # For cross buidling our images |
| 34 | + # This is necessary because travis-ci.org has only x86_64 machines. |
| 35 | + # If travis-ci.org gets native arm builds, probably this step is not |
| 36 | + # necessary any more. |
| 37 | + - docker run --rm --privileged multiarch/qemu-user-static:register --reset |
| 38 | + # Bats is necessary for the UT |
| 39 | + - curl -o bats.tar.gz -SL https://github.com/bats-core/bats-core/archive/v1.1.0.tar.gz |
| 40 | + - mkdir bats-core && tar -xf bats.tar.gz -C bats-core --strip-components=1 |
| 41 | + - cd bats-core/ |
| 42 | + - sudo ./install.sh /usr/local |
| 43 | + - cd .. |
| 44 | + |
| 45 | +before_script: |
| 46 | + # Set baseimage. |
| 47 | + - sed -i -e "s/FROM \(.*\)/FROM \1-${TARGET_ARCH}/g" image/Dockerfile; |
| 48 | + - cat image/Dockerfile; |
| 49 | + # If this is a tag then change the VERSION variable to only have the |
| 50 | + # tag name and not also the commit hash. |
| 51 | + - if [ -n "$TRAVIS_TAG" ]; then |
| 52 | + VERSION=$(echo "${TRAVIS_TAG}" | sed -e 's/\(.*\)[-v]\(.*\)/\1\2/g'); |
| 53 | + fi |
| 54 | + - if [ "${TRAVIS_BRANCH}" == 'stable' ]; then |
| 55 | + VERSION="stable"; |
| 56 | + fi |
| 57 | + |
| 58 | +script: |
| 59 | + - make build-nocache NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} |
| 60 | + # Run the test and if the test fails mark the build as failed. |
| 61 | + - make test NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} |
| 62 | + |
| 63 | +before_deploy: |
| 64 | + - docker run -d --name test_image ${NAME}:${VERSION}-${TARGET_ARCH} sleep 10 |
| 65 | + - sleep 5 |
| 66 | + - sudo docker ps | grep -q test_image |
| 67 | + # To have `DOCKER_USER` and `DOCKER_PASS` |
| 68 | + # use `travis env set`. |
| 69 | + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; |
| 70 | + - make tag NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} |
| 71 | + |
| 72 | +deploy: |
| 73 | + provider: script |
| 74 | + on: |
| 75 | + all_branches: true |
| 76 | + script: make push NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} |
| 77 | + |
| 78 | +jobs: |
| 79 | + include: |
| 80 | + - stage: Manifest creation |
| 81 | + install: skip |
| 82 | + script: skip |
| 83 | + after_deploy: |
| 84 | + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; |
| 85 | + - docker manifest create ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8; |
| 86 | + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 --os linux --arch amd64; |
| 87 | + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7; |
| 88 | + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8; |
| 89 | + |
| 90 | + # The latest tag is coming from the stable branch of the repo |
| 91 | + - if [ "${TRAVIS_BRANCH}" == 'stable' ]; then |
| 92 | + docker manifest create ${NAME}:latest ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8; |
| 93 | + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-amd64 --os linux --arch amd64; |
| 94 | + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7; |
| 95 | + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8; |
| 96 | + fi |
| 97 | + |
| 98 | + - docker manifest push ${NAME}:${VERSION}; |
| 99 | + if [ "${TRAVIS_BRANCH}" == 'stable' ]; then |
| 100 | + docker manifest push ${NAME}:latest; |
| 101 | + fi |
0 commit comments