-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from mozilla/update-dockerfile-and-circleyml
Dockerfile updated to be based on python, circle building properly
- Loading branch information
Showing
3 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
# Dockerfile for socorro-collector container | ||
FROM centos:centos7 | ||
FROM python:2.7.12-slim | ||
|
||
# Set Python-related environment variables to reduce annoying-ness | ||
ENV PYTHONUNBUFFERED 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
WORKDIR /app/ | ||
RUN groupadd --gid 1001 app && useradd -g app --uid 1001 --shell /usr/sbin/nologin app | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
gcc apt-transport-https | ||
|
||
EXPOSE 8000 | ||
COPY ./requirements.txt /app/requirements.txt | ||
COPY requirements-dev.txt /app/requirements-dev.txt | ||
|
||
# Install pip and get pip8 | ||
RUN yum -y install epel-release \ | ||
&& yum -y update \ | ||
&& yum -y group install "Development Tools" \ | ||
&& yum -y install python-devel python-pip | ||
COPY bin/pipstrap.py bin/pipstrap.py | ||
RUN ./bin/pipstrap.py | ||
RUN pip install -U 'pip>=8' && \ | ||
pip install --upgrade --no-cache-dir -r requirements.txt | ||
|
||
# Install the app | ||
COPY . /app/ | ||
WORKDIR /app/ | ||
|
||
# Install everything--but do it in a way that busts the cache | ||
# if certain files change | ||
ADD requirements.txt /app/requirements.txt | ||
ADD requirements-dev.txt /app/requirements-dev.txt | ||
# Set Python-related environment variables to reduce annoying-ness | ||
ENV PYTHONUNBUFFERED 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PORT 8000 | ||
|
||
USER app | ||
EXPOSE $PORT | ||
|
||
RUN pip install --require-hashes -r requirements-dev.txt \ | ||
&& pip install -e . | ||
CMD ANTENNA_INI=settings_dev.ini gunicorn \ | ||
--workers=1 \ | ||
--worker-connections=4 \ | ||
--worker-class=gevent \ | ||
--bind localhost:${PORT} \ | ||
antenna.wsgi:application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# THIS IS MEANT TO BE RUN BY CI | ||
|
||
set -e | ||
|
||
# Usage: retry MAX CMD... | ||
# Retry CMD up to MAX times. If it fails MAX times, returns failure. | ||
# Example: retry 3 docker push "mozilla/antenna:$TAG" | ||
function retry() { | ||
max=$1 | ||
shift | ||
count=1 | ||
until "$@"; do | ||
count=$((count + 1)) | ||
if [[ $count -gt $max ]]; then | ||
return 1 | ||
fi | ||
echo "$count / $max" | ||
done | ||
return 0 | ||
} | ||
|
||
# configure docker creds | ||
retry 3 docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" | ||
|
||
# docker tag and push git branch to dockerhub | ||
if [ -n "$1" ]; then | ||
[ "$1" == master ] && TAG=latest || TAG="$1" | ||
docker tag antenna:build "mozilla/antenna:$TAG" || | ||
(echo "Couldn't tag antenna:build as mozilla/antenna:$TAG" && false) | ||
retry 3 docker push "mozilla/antenna:$TAG" || | ||
(echo "Couldn't push mozilla/antenna:$TAG" && false) | ||
echo "Pushed mozilla/antenna:$TAG" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
machine: | ||
services: | ||
- docker | ||
|
||
dependencies: | ||
cache_directories: | ||
- "~/cache/" | ||
override: | ||
# create a version.json per https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md | ||
- > | ||
printf '{"commit":"%s","version":"%s","source":"https://github.com/%s/%s","build":"%s"}\n' | ||
"$CIRCLE_SHA1" | ||
"$CIRCLE_TAG" | ||
"$CIRCLE_PROJECT_USERNAME" | ||
"$CIRCLE_PROJECT_REPONAME" | ||
"$CIRCLE_BUILD_URL" > version.json | ||
- cp version.json $CIRCLE_ARTIFACTS | ||
- docker info | ||
# use circleci's docker cache workaround | ||
- mkdir -p ~/cache/ | ||
- if [ -e ~/cache/docker/image.tar ]; then echo "Loading image.tar"; docker load -i ~/cache/docker/image.tar || rm ~/cache/docker/image.tar; fi | ||
# build image | ||
- docker build -t antenna:build . | ||
# Clean up old image and save the new one | ||
- > | ||
mkdir -p ~/cache/docker; | ||
rm -f ~/cache/docker/image.tar; | ||
docker save antenna:build > ~/cache/docker/image.tar; | ||
ls -l ~/cache/docker | ||
test: | ||
pre: | ||
- chmod -R 777 $CIRCLE_TEST_REPORTS | ||
- pip install tox | ||
override: | ||
# Run Python tests | ||
- tox -e flake8 | ||
- tox -e tests | ||
|
||
# appropriately tag and push the container to dockerhub | ||
deployment: | ||
latest: | ||
branch: master | ||
commands: | ||
# set DOCKER_DEPLOY=true in Circle UI to do deploys | ||
- "${DOCKER_DEPLOY:-false}" | ||
- bin/ci/deploy-dockerhub.sh latest | ||
|
||
tags: | ||
# push all tags | ||
tag: /.*/ | ||
commands: | ||
# set DOCKER_DEPLOY=true in Circle UI to do deploys | ||
- "${DOCKER_DEPLOY:-false}" | ||
- bin/ci/deploy-dockerhub.sh "$CIRCLE_TAG" | ||
|
||
# this is just for dev / testing | ||
hub_all: | ||
branch: /.*/ | ||
commands: | ||
# set DOCKER_DEPLOY=true in Circle UI to do deploys | ||
- "${DOCKER_DEPLOY:-false}" | ||
- bin/ci/deploy-dockerhub.sh unstable |