diff --git a/.travis.yml b/.travis.yml index ba5cd935..0c4e3316 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,54 +1,80 @@ -sudo: required - -language: generic +language: bash services: - docker - env: global: - - qemu_version=4.0.0 - - target_version=1.1.2 + - NAME="osixia/light-baseimage" + - VERSION="${TRAVIS_BRANCH}-${TRAVIS_COMMIT}" matrix: - - target_arch=amd64 qemu_arch=x86_64 - - target_arch=armv7 qemu_arch=arm -# - target_arch=armv6 qemu_arch=arm <------ NOT SUPPORTED BY DEBIAN STRETCH BASE IMAGE - - target_arch=arm64 qemu_arch=aarch64 + - TARGET_ARCH=amd64 QEMU_ARCH=x86_64 + - TARGET_ARCH=i386 QEMU_ARCH=i386 + - TARGET_ARCH=arm32v7 QEMU_ARCH=arm + - TARGET_ARCH=arm64v8 QEMU_ARCH=aarch64 + +addons: + apt: + # The docker manifest command was added in docker-ee version 18.x + # So update our current installation and we also have to enable the experimental features. + sources: + - sourceline: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable' + key_url: 'https://download.docker.com/linux/ubuntu/gpg' + packages: + - docker-ce before_install: - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - - sudo apt-get update - - sudo apt-get -y install docker-ce + - docker --version - mkdir $HOME/.docker - 'echo "{" > $HOME/.docker/config.json' - 'echo " \"experimental\": \"enabled\"" >> $HOME/.docker/config.json' - 'echo "}" >> $HOME/.docker/config.json' - sudo service docker restart - - git clone https://github.com/sstephenson/bats.git - - cd bats + +install: + # For cross buidling our images + # This is necessary because travis-ci.org has only x86_64 machines. + # If travis-ci.org gets native arm builds, probably this step is not + # necessary any more. + - docker run --rm --privileged multiarch/qemu-user-static:register --reset + # Bats is necessary for the UT + - curl -o bats.tar.gz -SL https://github.com/bats-core/bats-core/archive/v1.1.0.tar.gz + - mkdir bats-core && tar -xf bats.tar.gz -C bats-core --strip-components=1 + - cd bats-core/ - sudo ./install.sh /usr/local - cd .. -install: - - docker run --rm --privileged multiarch/qemu-user-static:register - - curl -sLO https://github.com/multiarch/qemu-user-static/releases/download/v${qemu_version}/qemu-${qemu_arch}-static.tar.gz; - - tar -xzvf qemu-${qemu_arch}-static.tar.gz; - - mv qemu-${qemu_arch}-static image/ - - make build ARCH=${target_arch} +before_script: + # Injecting the necessary information and binaries for cross-compiling the images. + # In native builds this information and binaries are not necessary and that is why + # we are injecting them in the build scripts and we do not include them in the Dockerfiles + - if [[ "${TARGET_ARCH}" != 'amd64' ]]; then + sed -i "s/FROM debian/FROM ${TARGET_ARCH}\/debian/" image/Dockerfile; + fi + - if [[ "${TARGET_ARCH}" != 'amd64' ]]; then + sed -i "/${TARGET_ARCH}\/debian/a COPY \ + --from=multiarch/qemu-user-static:x86_64-${QEMU_ARCH} \ + /usr/bin/qemu-${QEMU_ARCH}-static /usr/bin/" image/Dockerfile; + fi + - cat image/Dockerfile; + # If this is a tag then change the VERSION variable to only have the + # tag name and not also the commit hash. + - if [ -n "$TRAVIS_TAG" ]; then + VERSION="${TRAVIS_TAG}"; + fi script: - - docker run -d --name test_image osixia/light-baseimage-${target_arch}:${target_version} sleep 10 - - sleep 5 - - sudo docker ps | grep -q test_image + - make build-nocache NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} after_success: - - if [ -z "$DOCKER_USER" ]; then - echo "PR build, skipping Docker Hub push"; - else - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; - make tag-latest push push-latest ARCH=${target_arch}; - fi + - make test NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} + - docker run -d --name test_image ${NAME}:${VERSION}-${TARGET_ARCH} sleep 10 + - sleep 5 + - sudo docker ps | grep -q test_image + # To have `DOCKER_USER` and `DOCKER_PASS` + # use `travis env set`. + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; + - make tag NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} + - make push NAME=${NAME} VERSION=${VERSION}-${TARGET_ARCH} jobs: include: @@ -56,12 +82,24 @@ jobs: install: skip script: skip after_success: - - if [ -z "$DOCKER_USER" ]; then - echo "PR build, skipping Docker Hub push"; - else - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; - docker manifest create osixia/light-baseimage:${target_version} osixia/light-baseimage-armv7:${target_version} osixia/light-baseimage-arm64:${target_version} osixia/light-baseimage-amd64:${target_version}; - docker manifest create osixia/light-baseimage:latest osixia/light-baseimage-armv7:latest osixia/light-baseimage-amd64:latest osixia/light-baseimage-arm64:latest; - docker manifest push osixia/light-baseimage:${target_version}; - docker manifest push osixia/light-baseimage:latest; + - docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"; + - docker manifest create ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-i386 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8; + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-amd64 --os linux --arch amd64; + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-i386 --os linux --arch 386; + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7; + docker manifest annotate ${NAME}:${VERSION} ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8; + + # The latest tag is coming from the stable branch of the repo + - if [ "${TRAVIS_BRANCH}" == 'stable' ]; then + docker manifest create ${NAME}:latest ${NAME}:${VERSION}-amd64 ${NAME}:${VERSION}-i386 ${NAME}:${VERSION}-arm32v7 ${NAME}:${VERSION}-arm64v8; + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-amd64 --os linux --arch amd64; + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-i386 --os linux --arch 386; + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm32v7 --os linux --arch arm --variant v7; + docker manifest annotate ${NAME}:latest ${NAME}:${VERSION}-arm64v8 --os linux --arch arm64 --variant v8; + fi + + - docker manifest push ${NAME}:${VERSION}; + if [ "${TRAVIS_BRANCH}" == 'stable' ]; then + docker manifest push ${NAME}:latest; fi + diff --git a/Makefile b/Makefile index eefcf2e1..b3bc5b7f 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,28 @@ NAME = osixia/light-baseimage -VERSION = 1.2.0 -ARCH = amd64 +VERSION = latest .PHONY: build build-nocache test tag-latest push push-latest release git-tag-version build: - docker build -f image/Dockerfile.$(ARCH) -t $(NAME)-$(ARCH):$(VERSION) --rm image + docker build -f image/Dockerfile -t $(NAME):$(VERSION) --rm image build-nocache: - docker build -f image/Dockerfile.$(ARCH) -t $(NAME)-$(ARCH):$(VERSION) --no-cache --rm image + docker build -f image/Dockerfile -t $(NAME):$(VERSION) --no-cache --rm image test: - env NAME=$(NAME)-$(ARCH) VERSION=$(VERSION) bats test/test.bats + env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats + +tag: + docker tag $(NAME):$(VERSION) $(NAME):$(VERSION) tag-latest: - docker tag $(NAME)-$(ARCH):$(VERSION) $(NAME)-$(ARCH):latest + docker tag $(NAME):$(VERSION) $(NAME):latest push: - docker push $(NAME)-$(ARCH):$(VERSION) + docker push $(NAME):$(VERSION) push-latest: - docker push $(NAME)-$(ARCH):latest + docker push $(NAME):latest release: build test tag-latest push push-latest diff --git a/README.md b/README.md index e6704364..e9e6c61c 100644 --- a/README.md +++ b/README.md @@ -859,7 +859,7 @@ Can also be set by command line converted in python or json: We use **Bats** (Bash Automated Testing System) to test this image: -> [https://github.com/sstephenson/bats](https://github.com/sstephenson/bats) +> [https://github.com/bats-core/bats-core](https://github.com/bats-core/bats-core) Install Bats, and in this project directory run: diff --git a/image/Dockerfile.old b/image/Dockerfile similarity index 100% rename from image/Dockerfile.old rename to image/Dockerfile diff --git a/image/Dockerfile.amd64 b/image/Dockerfile.amd64 deleted file mode 100644 index 606e2fdd..00000000 --- a/image/Dockerfile.amd64 +++ /dev/null @@ -1,12 +0,0 @@ -FROM debian:stretch-slim - -#COPY qemu-x86_64-static /usr/bin - -COPY . /container -RUN /container/build.sh - -ENV LANG="en_US.UTF-8" \ - LANGUAGE="en_US:en" \ - LC_ALL="en_US.UTF-8" - -ENTRYPOINT ["/container/tool/run"] diff --git a/image/Dockerfile.arm64 b/image/Dockerfile.arm64 deleted file mode 100644 index 8596127b..00000000 --- a/image/Dockerfile.arm64 +++ /dev/null @@ -1,12 +0,0 @@ -FROM arm64v8/debian:stretch-slim - -COPY qemu-aarch64-static /usr/bin - -COPY . /container -RUN /container/build.sh - -ENV LANG="en_US.UTF-8" \ - LANGUAGE="en_US:en" \ - LC_ALL="en_US.UTF-8" - -ENTRYPOINT ["/container/tool/run"] diff --git a/image/Dockerfile.armv7 b/image/Dockerfile.armv7 deleted file mode 100644 index a6cabe4a..00000000 --- a/image/Dockerfile.armv7 +++ /dev/null @@ -1,12 +0,0 @@ -FROM arm32v7/debian:stretch-slim - -COPY qemu-arm-static /usr/bin - -COPY . /container -RUN /container/build.sh - -ENV LANG="en_US.UTF-8" \ - LANGUAGE="en_US:en" \ - LC_ALL="en_US.UTF-8" - -ENTRYPOINT ["/container/tool/run"]