Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the Bats version and changing the travis.yml #14

Merged
merged 3 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 77 additions & 39 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,105 @@
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:
- stage: deploy
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

18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
File renamed without changes.
12 changes: 0 additions & 12 deletions image/Dockerfile.amd64

This file was deleted.

12 changes: 0 additions & 12 deletions image/Dockerfile.arm64

This file was deleted.

12 changes: 0 additions & 12 deletions image/Dockerfile.armv7

This file was deleted.