Skip to content

Commit

Permalink
Merge pull request #111 from pyouroboros/multiarch/fine-tuning
Browse files Browse the repository at this point in the history
Multiarch/fine tuning
  • Loading branch information
dirtycajunrice authored Jan 17, 2019
2 parents 1327eb7 + 9ce80f5 commit 75d1a41
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 77 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
sudo: true
dist: xenial
language: python
python:
- 3.6
- 3.7.2
services:
- docker
addons:
Expand All @@ -20,8 +21,11 @@ deploy:
skip_existing: true
on:
branch: master

- provider: script
script: bash ./deploy.sh
script: bash deploy.sh
on:
branch: master
- provider: script
script: bash deploy.sh
on:
branch: develop
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FROM python:3.7-alpine
FROM amd64/python:3.7.2-alpine

LABEL maintainers="dirtycajunrice,circa10a,tkdeviant"

COPY / /app

WORKDIR /app
COPY . .

RUN apk add --no-cache tzdata && \
pip install --no-cache-dir .
ENTRYPOINT ["ouroboros"]

ENTRYPOINT ["ouroboros"]
7 changes: 0 additions & 7 deletions Dockerfile-arm32v7.rpi

This file was deleted.

7 changes: 0 additions & 7 deletions Dockerfile-arm64v8.rpi

This file was deleted.

14 changes: 14 additions & 0 deletions Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM arm32v6/python:3.7.2-alpine

LABEL maintainers="dirtycajunrice,circa10a,tkdeviant"

COPY / /app

COPY /tmp/qemu-arm-static /usr/bin/qemu-arm-static

WORKDIR /app

RUN apk add --no-cache tzdata && \
pip install --no-cache-dir .

ENTRYPOINT ["ouroboros"]
14 changes: 14 additions & 0 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM arm64v8/python:3.7.2-alpine

LABEL maintainers="dirtycajunrice,circa10a,tkdeviant"

COPY / /app

COPY /tmp/qemu-aarch64-static /usr/bin/qemu-aarch64-static

WORKDIR /app

RUN apk add --no-cache tzdata && \
pip install --no-cache-dir .

ENTRYPOINT ["ouroboros"]
13 changes: 13 additions & 0 deletions Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM arm32v7/python:3.7.2-slim

LABEL maintainers="dirtycajunrice,circa10a,tkdeviant"

COPY / /app

COPY /tmp/qemu-arm-static /usr/bin/qemu-arm-static

WORKDIR /app

RUN pip install --no-cache-dir .

ENTRYPOINT ["ouroboros"]
118 changes: 82 additions & 36 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,96 @@
#!/usr/bin/env bash
VERSION="$(grep -i version ./pyouroboros/__init__.py | awk -F= '{gsub("\047",""); gsub(",",""); print $2}')"
# 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

# Docker
GITHUB_USER='pyouroboros-bot'
DOCKER_USER='pyouroborosbot'
PROJECT='ouroboros'
NAMESPACE="pyouroboros/${PROJECT}"
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
[[ -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

# Latest x64
docker build -t "${NAMESPACE}:latest" . && \
docker push "${NAMESPACE}:latest" && \
# Versioned x64
docker tag "${NAMESPACE}:latest" "${NAMESPACE}:${VERSION}" && \
docker push "${NAMESPACE}:${VERSION}" && \
# x64 Arch
docker tag "${NAMESPACE}:latest" "${NAMESPACE}:latest-amd64" && \
docker push "${NAMESPACE}:latest-amd64"

# Prepare qemu for ARM builds
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

# ARM images
for i in $(ls *.rpi); do
arch="$(echo ${i} | cut -d- -f2 | cut -d. -f1)"
# Latest
docker build -f "./Dockerfile-${arch}.rpi" -t "${NAMESPACE}:latest-${arch}-rpi" . && \
docker push "${NAMESPACE}:latest-${arch}-rpi" && \
# Versioned
docker tag "${NAMESPACE}:latest-${arch}-rpi" "${NAMESPACE}:${VERSION}-${arch}-rpi" && \
docker push "${NAMESPACE}:${VERSION}-${arch}-rpi"
# 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 annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v8
if [[ "$BRANCH" == "latest" ]]; then
docker annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v8
fi
elif [[ "$ARCH" == "armhf" ]]; then
docker annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v7
if [[ "$BRANCH" == "latest" ]]; then
docker annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v7
fi
elif [[ "$ARCH" == "arm" ]]; then
docker annotate "${REPOSITORY}:${BRANCH}" "${REPOSITORY}:${BRANCH}-${ARCH}" --variant v6
if [[ "$BRANCH" == "latest" ]]; then
docker annotate "${REPOSITORY}:${TAG}" "${REPOSITORY}:${TAG}-${ARCH}" --variant v6
fi
fi
done

wget -O manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.9.0/manifest-tool-linux-amd64 && \
chmod +x manifest-tool && \
./manifest-tool --username "$USER" --password "$docker_password" push from-spec "${USER}-${PROJECT}.yaml"
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
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_API_KEY}@github.com/${NAMESPACE}.git" && \
git tag "${VERSION}" && \
git push --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
19 changes: 0 additions & 19 deletions pyouroboros-ouroboros.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion pyouroboros/notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def send(self, container_tuples, socket):
CONTAINER_UPDATES=container_updates)

msg.set_content(template)
server = self.get_server()
try:
server = self.get_server()
server.send_message(msg)
except SMTPServerDisconnected as e:
self.server = False
Expand Down
2 changes: 1 addition & 1 deletion pyouroboros/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main():
help='SMTP relay port\n'
'EXAMPLE: -E 587')

notification_group.add_argument('-f', '--smtp-starttls', default=False, dest='SMTP_HOST', action='store_true',
notification_group.add_argument('-f', '--smtp-starttls', default=False, dest='SMTP_STARTTLS', action='store_true',
help='SMTP relay uses STARTTLS')

notification_group.add_argument('-F', '--smtp-username', default=Config.smtp_username, dest='SMTP_USERNAME',
Expand Down

0 comments on commit 75d1a41

Please sign in to comment.