Skip to content

Commit

Permalink
Do not use captain for the build
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicc committed Apr 9, 2019
1 parent 4941391 commit 78b9100
Show file tree
Hide file tree
Showing 20 changed files with 209 additions and 132 deletions.
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
sha: v0.7.1
rev: v2.1.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: .bumpversion.cfg
- id: check-merge-conflict
- id: check-added-large-files
- id: check-yaml
- id: check-json
- id: pretty-format-json
args: ["--autofix"]
exclude: slack.json
1 change: 1 addition & 0 deletions python-base-build/.dockerimage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMAGE=hbpmip/python-base-build
2 changes: 1 addition & 1 deletion python-base-build/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*~
.idea/
.idea/
10 changes: 4 additions & 6 deletions python-base-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
FROM continuumio/miniconda3:4.3.27

MAINTAINER [email protected]

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

COPY requirements-dev.txt /

RUN pip install -r /requirements-dev.txt
Expand All @@ -22,6 +16,10 @@ RUN apt-get update && \

RUN pip install git+https://github.com/Marigold/hadrian.git@light#subdirectory=titus

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="hbpmip/python-base-build" \
org.label-schema.description="Base Python image including Conda" \
Expand Down
24 changes: 15 additions & 9 deletions python-base-build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ get_script_dir () {

cd "$(get_script_dir)"

if [[ $NO_SUDO || -n "$CIRCLECI" ]]; then
CAPTAIN="captain"
elif groups $USER | grep &>/dev/null '\bdocker\b'; then
CAPTAIN="captain"
if [[ "$NO_SUDO" || -n "$CIRCLECI" ]]; then
DOCKER="docker"
elif groups "$USER" | grep &>/dev/null '\bdocker\b'; then
DOCKER="docker"
else
CAPTAIN="sudo captain"
DOCKER="sudo docker"
fi

BUILD_DATE=$(date -Iseconds) \
VCS_REF=$(git describe --tags --dirty) \
VERSION=$(git describe --tags --dirty) \
$CAPTAIN build
source ./.dockerimage
VCS_REF=$(git describe --tags --dirty | sed 's/python-base-build-//')
VERSION=$(git describe --tags --dirty | sed 's/python-base-build-//')

docker build --build-arg BUILD_DATE=$(date -Iseconds) \
--build-arg VCS_REF=$VCS_REF \
--build-arg VERSION=$VERSION \
--tag "$IMAGE:latest" \
--tag "$IMAGE:$VERSION" \
.
9 changes: 0 additions & 9 deletions python-base-build/captain.yml

This file was deleted.

47 changes: 33 additions & 14 deletions python-base-build/publish.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

#
# Build the release image for the project and publish it on Dockerhub, then
# announce the new version on Slack
#
# Option:
# --no-tests: skip the test suite

set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
Expand All @@ -24,17 +31,28 @@ if pgrep -lf sshuttle > /dev/null ; then
fi

if [ $NO_SUDO ]; then
CAPTAIN="captain"
elif groups $USER | grep &>/dev/null '\bdocker\b'; then
CAPTAIN="captain"
DOCKER="docker"
elif groups "$USER" | grep &>/dev/null '\bdocker\b'; then
DOCKER="docker"
else
CAPTAIN="sudo captain"
DOCKER="sudo docker"
fi

tests=1
for param in "$@"
do
if [ "--no-tests" == "$param" ]; then
tests=0
echo "INFO: --no-tests option detected !"
fi
done

# Build
echo "Build the project..."
./build.sh
./tests/test.sh
if [ $tests == 1 ]; then
./tests/test.sh
fi
echo "[ok] Done"

count=$(git status --porcelain | wc -l)
Expand Down Expand Up @@ -91,20 +109,21 @@ updated_version=$(bumpversion --dry-run --list patch | grep current_version | se
# Build again to update the version
echo "Build the project for distribution..."
./build.sh
./tests/test.sh
if [ $tests == 1 ]; then
./tests/test.sh
fi
echo "[ok] Done"

# Push on Docker Hub
echo
echo "Publishing..."
source ./.dockerimage
$DOCKER push "$IMAGE:latest"
$DOCKER push "$IMAGE:$updated_version"

git push
git push --tags

# Push on Docker Hub
# WARNING: Requires captain 1.1.0 to push user tags
BUILD_DATE=$(date -Iseconds) \
VCS_REF=$updated_version \
VERSION=$updated_version \
WORKSPACE=$WORKSPACE \
$CAPTAIN push target_image --branch-tags=false --commit-tags=false --tag $updated_version

# Notify on slack
sed "s/USER/${USER^}/" $WORKSPACE/slack.json > $WORKSPACE/.slack.json
sed -i.bak "s/VERSION/$updated_version/" $WORKSPACE/.slack.json
Expand Down
1 change: 1 addition & 0 deletions python-base/.dockerimage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMAGE=hbpmip/python-base
2 changes: 1 addition & 1 deletion python-base/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*~
.idea/
.idea/
2 changes: 0 additions & 2 deletions python-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM python:3.6.2-slim

MAINTAINER [email protected]

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
Expand Down
24 changes: 15 additions & 9 deletions python-base/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ get_script_dir () {

cd "$(get_script_dir)"

if [[ $NO_SUDO || -n "$CIRCLECI" ]]; then
CAPTAIN="captain"
elif groups $USER | grep &>/dev/null '\bdocker\b'; then
CAPTAIN="captain"
if [[ "$NO_SUDO" || -n "$CIRCLECI" ]]; then
DOCKER="docker"
elif groups "$USER" | grep &>/dev/null '\bdocker\b'; then
DOCKER="docker"
else
CAPTAIN="sudo captain"
DOCKER="sudo docker"
fi

BUILD_DATE=$(date -Iseconds) \
VCS_REF=$(git describe --tags --dirty) \
VERSION=$(git describe --tags --dirty) \
$CAPTAIN build
source ./.dockerimage
VCS_REF=$(git describe --tags --dirty | sed 's/python-base-//')
VERSION=$(git describe --tags --dirty | sed 's/python-base-//')

docker build --build-arg BUILD_DATE=$(date -Iseconds) \
--build-arg VCS_REF=$VCS_REF \
--build-arg VERSION=$VERSION \
--tag "$IMAGE:latest" \
--tag "$IMAGE:$VERSION" \
.
9 changes: 0 additions & 9 deletions python-base/captain.yml

This file was deleted.

47 changes: 33 additions & 14 deletions python-base/publish.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

#
# Build the release image for the project and publish it on Dockerhub, then
# announce the new version on Slack
#
# Option:
# --no-tests: skip the test suite

set -o pipefail # trace ERR through pipes
set -o errtrace # trace ERR through 'time command' and other functions
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
Expand All @@ -24,17 +31,28 @@ if pgrep -lf sshuttle > /dev/null ; then
fi

if [ $NO_SUDO ]; then
CAPTAIN="captain"
elif groups $USER | grep &>/dev/null '\bdocker\b'; then
CAPTAIN="captain"
DOCKER="docker"
elif groups "$USER" | grep &>/dev/null '\bdocker\b'; then
DOCKER="docker"
else
CAPTAIN="sudo captain"
DOCKER="sudo docker"
fi

tests=1
for param in "$@"
do
if [ "--no-tests" == "$param" ]; then
tests=0
echo "INFO: --no-tests option detected !"
fi
done

# Build
echo "Build the project..."
./build.sh
./tests/test.sh
if [ $tests == 1 ]; then
./tests/test.sh
fi
echo "[ok] Done"

count=$(git status --porcelain | wc -l)
Expand Down Expand Up @@ -91,20 +109,21 @@ updated_version=$(bumpversion --dry-run --list patch | grep current_version | se
# Build again to update the version
echo "Build the project for distribution..."
./build.sh
./tests/test.sh
if [ $tests == 1 ]; then
./tests/test.sh
fi
echo "[ok] Done"

# Push on Docker Hub
echo
echo "Publishing..."
source ./.dockerimage
$DOCKER push "$IMAGE:latest"
$DOCKER push "$IMAGE:$updated_version"

git push
git push --tags

# Push on Docker Hub
# WARNING: Requires captain 1.1.0 to push user tags
BUILD_DATE=$(date -Iseconds) \
VCS_REF=$updated_version \
VERSION=$updated_version \
WORKSPACE=$WORKSPACE \
$CAPTAIN push target_image --branch-tags=false --commit-tags=false --tag $updated_version

# Notify Microbadger
curl -XPOST https://hooks.microbadger.com/images/hbpmip/python-base/Nenr0kul69G7EeOETA8jZT6th24=

Expand Down
1 change: 1 addition & 0 deletions python-mip-sklearn/.dockerimage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMAGE=hbpmip/python-mip-sklearn
26 changes: 15 additions & 11 deletions python-mip-sklearn/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,28 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends git && \
rm -rf /tmp/* /var/tmp/* /var/cache/* /var/lib/apt/lists/*

COPY requirements.txt /
COPY docker-entrypoint.sh /

RUN pip install -r /requirements.txt
RUN pip install git+https://github.com/Marigold/hadrian.git@light#subdirectory=titus

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["compute"]

ARG BUILD_DATE
ARG VCS_REF
ARG VERSION

LABEL org.label-schema.build-date=$BUILD_DATE \
org.label-schema.name="hbpmip/python-mip-sklearn" \
org.label-schema.description="Execute Python algorithms in MIP Woken environment" \
org.label-schema.url="https://github.com/LREN-CHUV/python-base-docker-images" \
org.label-schema.vcs-type="git" \
org.label-schema.vcs-url="https://github.com/LREN-CHUV/python-base-docker-images.git" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-ref="$VCS_REF" \
org.label-schema.version="$VERSION" \
org.label-schema.vendor="LREN CHUV" \
org.label-schema.license="AGPLv3" \
org.label-schema.license="Apache2.0" \
org.label-schema.docker.dockerfile="Dockerfile" \
org.label-schema.schema-version="1.0"

COPY requirements.txt /
COPY docker-entrypoint.sh /

RUN pip install -r /requirements.txt
RUN pip install git+https://github.com/Marigold/hadrian.git@light#subdirectory=titus

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["compute"]
Loading

0 comments on commit 78b9100

Please sign in to comment.