.travis.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. language: bash
  2. services:
  3. - docker
  4. env:
  5. global:
  6. - NAME="osixia/light-baseimage"
  7. - VERSION="${TRAVIS_BRANCH}-dev"
  8. matrix:
  9. - TARGET_ARCH=amd64 QEMU_ARCH=x86_64
  10. - TARGET_ARCH=i386 QEMU_ARCH=i386
  11. - TARGET_ARCH=arm32v7 QEMU_ARCH=arm
  12. - TARGET_ARCH=arm64v8 QEMU_ARCH=aarch64
  13. addons:
  14. apt:
  15. # The docker manifest command was added in docker-ee version 18.x
  16. # So update our current installation and we also have to enable the experimental features.
  17. sources:
  18. - sourceline: "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  19. key_url: "https://download.docker.com/linux/ubuntu/gpg"
  20. packages:
  21. - docker-ce
  22. before_install:
  23. - docker --version
  24. - mkdir $HOME/.docker
  25. - 'echo "{" > $HOME/.docker/config.json'
  26. - 'echo " \"experimental\": \"enabled\"" >> $HOME/.docker/config.json'
  27. - 'echo "}" >> $HOME/.docker/config.json'
  28. - sudo service docker restart
  29. # To have `DOCKER_USER` and `DOCKER_PASS`
  30. # use `travis env set`.
  31. - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
  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. before_script:
  45. # Injecting the necessary information and binaries for cross-compiling the images.
  46. # In native builds this information and binaries are not necessary and that is why
  47. # we are injecting them in the build scripts and we do not include them in the Dockerfiles
  48. - if [[ "${TARGET_ARCH}" != 'amd64' ]]; then
  49. sed -i "s/FROM alpine/FROM ${TARGET_ARCH}\/alpine/" image/Dockerfile;
  50. fi
  51. - if [[ "${TARGET_ARCH}" != 'amd64' ]]; then
  52. sed -i "/${TARGET_ARCH}\/alpine/a COPY \
  53. --from=multiarch/qemu-user-static:x86_64-${QEMU_ARCH} \
  54. /usr/bin/qemu-${QEMU_ARCH}-static /usr/bin/" image/Dockerfile;
  55. fi
  56. - cat image/Dockerfile;
  57. # If this is a tag then change the VERSION variable to only have the
  58. # tag name and not also the commit hash.
  59. - if [ -n "$TRAVIS_TAG" ]; then
  60. VERSION=$(echo "${TRAVIS_TAG}" | sed -e 's/\(.*\)[-v]\(.*\)/\1\2/g');
  61. fi
  62. - if [ "${TRAVIS_BRANCH}" == 'master' ]; then
  63. VERSION="stable";
  64. fi
  65. # replace / with - in version
  66. - VERSION=$(echo "${VERSION}" | sed 's|/|-|g');
  67. script:
  68. - make build-nocache NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH}
  69. # Run the test and if the test fails mark the build as failed.
  70. - make test NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH}
  71. before_deploy:
  72. - docker run -d --name test_image ${NAME}:${VERSION}-${TARGET_ARCH} sleep 10
  73. - sleep 5
  74. - sudo docker ps | grep -q test_image
  75. - make tag NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH}
  76. deploy:
  77. provider: script
  78. on:
  79. all_branches: true
  80. script: make push NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH}
  81. jobs:
  82. include:
  83. - stage: Manifest creation
  84. install: skip
  85. script: skip
  86. after_deploy:
  87. - echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
  88. - docker manifest create ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-i386 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8;
  89. docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 --os linux --arch amd64;
  90. docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-i386 --os linux --arch 386;
  91. docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7;
  92. docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8;
  93. # The latest tag is coming from the stable branch of the repo
  94. - if [ "${TRAVIS_BRANCH}" == 'master' ]; then
  95. docker manifest create ${NAME}:latest ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-i386 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8;
  96. docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-amd64 --os linux --arch amd64;
  97. docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-i386 --os linux --arch 386;
  98. docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7;
  99. docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8;
  100. fi
  101. - docker manifest push ${NAME}:${VERSION};
  102. if [ "${TRAVIS_BRANCH}" == 'master' ]; then
  103. docker manifest push ${NAME}:latest;
  104. fi