forked from pyouroboros/ouroboros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·96 lines (84 loc) · 3.69 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Travis-ci convenience environment vars used:
# TRAVIS_BRANCH | branch name
# $TRAVIS_REPO_SLUG | organization/project (GitHub Capitalization)
# Travis-ci manual environment vars used:
# GITHUB_USER | github username
# GITHUB_TOKEN | $GITHUB_USER's token
# DOCKER_USER | docker username
# DOCKER_PASSWORD | $DOCKER_USER's password
VERSION="$(grep -i version pyouroboros/__init__.py | cut -d' ' -f3 | tr -d \")"
# Set branch to latest if master, else keep the same
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
BRANCH="latest"
else
BRANCH="$TRAVIS_BRANCH"
fi
# get the docker lowercase variant of the repo_name
REPOSITORY="$(echo $TRAVIS_REPO_SLUG | tr '[:upper:]' '[:lower:]')"
# Docker experimental config
echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json
[[ -d ~/.docker ]] || mkdir ~/.docker
[[ -f ~/.docker/config.json ]] || touch ~/.docker/config.json
echo '{"experimental":"enabled"}' | sudo tee ~/.docker/config.json
sudo service docker restart
# Auth
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin
# Prepare QEMU for ARM builds
docker run --rm --privileged multiarch/qemu-user-static:register --reset
wget -P tmp/ "https://github.com/multiarch/qemu-user-static/releases/download/v3.1.0-2/qemu-aarch64-static"
wget -P tmp/ "https://github.com/multiarch/qemu-user-static/releases/download/v3.1.0-2/qemu-arm-static"
chmod +x tmp/qemu-aarch64-static tmp/qemu-arm-static
# Set tag based off of branch
if [[ "$BRANCH" == "latest" ]]; then
TAG="$VERSION"
else
TAG="$BRANCH"
fi
# AMDx64
docker build -t "${REPOSITORY}:${TAG}-amd64" . && \
docker push "${REPOSITORY}:${TAG}-amd64"
# Create Initial Manifests
docker manifest create "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-amd64"
if [[ "$BRANCH" == "latest" ]]; then
docker manifest create "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-amd64"
fi
# ARM variants
for i in $(ls *arm*); do
ARCH="$(echo ${i} | cut -d. -f2)"
docker build -t "${REPOSITORY}:${TAG}-${ARCH}" . && \
docker push "${REPOSITORY}:${TAG}-${ARCH}"
# Add variant to manifest
docker manifest create -a "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}"
if [[ "$BRANCH" == "latest" ]]; then
docker manifest create -a "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}"
fi
if [[ "$ARCH" == "arm64" ]]; then
docker manifest annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v8 --arch arm64
if [[ "$BRANCH" == "latest" ]]; then
docker manifest annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v8 --arch arm64
fi
elif [[ "$ARCH" == "armhf" ]]; then
docker manifest annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v7 --arch arm
if [[ "$BRANCH" == "latest" ]]; then
docker manifest annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v7 --arch arm
fi
elif [[ "$ARCH" == "arm" ]]; then
docker manifest annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v6 --arch arm
if [[ "$BRANCH" == "latest" ]]; then
docker manifest annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v6 --arch arm
fi
fi
done
docker manifest inspect "${REPOSITORY}:${BRANCH}" && \
docker manifest push "${REPOSITORY}:${BRANCH}"
if [[ "$BRANCH" == "latest" ]]; then
docker manifest inspect "${REPOSITORY}:${TAG}" && \
docker manifest push "${REPOSITORY}:${TAG}"
fi
# Git tags
if [[ "$BRANCH" == "latest" ]]; then
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${REPOSITORY}.git" && \
git tag "${VERSION}" && \
git push --tags
fi