From c8bee45cf5cde937bb3d6821ab887947aebff615 Mon Sep 17 00:00:00 2001 From: yvanzo Date: Thu, 20 Jun 2019 20:40:58 +0200 Subject: [PATCH 1/2] Switch to in-house Solr base image Since version '7.7.2', the official Solr images support neither OpenJDK 8 nor the lightweight '-alpine' variant any longer. These are replaced by metabrainz/solr in-house image (7.2.2-alpine) based on adoptopenjdk/openjdk8 image (jre-alpine). See https://github.com/metabrainz/docker-openjdk8-solr7 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 033ccc2..62e4922 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM solr:7.7.2-alpine +FROM metabrainz/solr:7.7.2-alpine # Resetting value set in the parent image USER root From 7a7726c9f80f3a0e9569512900c4d3be29ad2d32 Mon Sep 17 00:00:00 2001 From: yvanzo Date: Thu, 20 Jun 2019 20:28:08 +0200 Subject: [PATCH 2/2] Split maven off from mb-solr final built image Maven was installed from Alpine Linux packages so as to install Java bindings for MB Metadata Schema (mmd-schema) and MB Query Response Writer (whose cores are defined by mbsssss). Instead, the build is split into two stages: - first stage is based on 'maven' official image (3.6.1-jdk-8) - second stage is based on 'metabrainz/solr' image (7.2.2-alpine) This way, final built image is smaller as it doesn't contain Maven. Versions, git ref, and build date have been added to image labels. Release script also updates tags with major and minor versions. --- .gitignore | 1 + Dockerfile | 45 +++++++++++++++++++++++++------------ push.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 95 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index a6f17cb..a052ff6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ mb-solr/target* .idea/ *.iml +/build-*.log diff --git a/Dockerfile b/Dockerfile index 62e4922..6ece0db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,8 @@ -FROM metabrainz/solr:7.7.2-alpine +ARG MAVEN_TAG=3.6.1-jdk-8 +ARG SOLR_NAME=metabrainz/solr +ARG SOLR_TAG=7.7.2-alpine -# Resetting value set in the parent image -USER root - -RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \ - apk add --update-cache --no-cache \ - bash \ - git \ - maven \ - openjdk8 \ - openssh +FROM maven:${MAVEN_TAG} AS builder # Caching the maven dependencies so that these are built only if # the dependencies are changed and not the source code. @@ -26,9 +19,33 @@ COPY ./mb-solr mb-solr RUN cd brainz-mmd2-jaxb && \ mvn install && \ cd ../mb-solr && \ - mvn package -DskipTests && \ - mkdir -p /opt/solr/lib && \ - cp target/mb-solr-0.0.1-SNAPSHOT-jar-with-dependencies.jar /opt/solr/lib + mvn package -DskipTests + +FROM ${SOLR_NAME}:${SOLR_TAG} + +ARG MAVEN_TAG +ARG SOLR_NAME +ARG SOLR_TAG + +ARG MB_SOLR_VERSION +ARG BUILD_DATE +ARG VCS_REF + +LABEL org.label-schema.build-date="${BUILD_DATE}" \ + org.label-schema.schema-version="1.0.0-rc1" \ + org.label-schema.vcs-ref="${VCS_REF}" \ + org.label-schema.vcs-url="https://github.com/metabrainz/mb-solr.git" \ + org.label-schema.vendor="MetaBrainz Foundation" \ + org.metabrainz.based-on-image="${SOLR_NAME}:${SOLR_TAG}" \ + org.metabrainz.builder-image="maven:${MAVEN_TAG}" \ + org.metabrainz.mb-solr.version="${MB_SOLR_VERSION}" + +# Resetting value set in the parent image +USER root + +COPY --from=builder \ + mb-solr/target/mb-solr-0.0.1-SNAPSHOT-jar-with-dependencies.jar \ + /opt/solr/lib/ ENV SOLR_HOME /opt/solr/server/solr COPY ./mbsssss $SOLR_HOME/mycores/mbsssss diff --git a/push.sh b/push.sh index d5bbfe0..67e73dc 100755 --- a/push.sh +++ b/push.sh @@ -1,4 +1,64 @@ -#!/bin/sh +#!/bin/bash +# +# Build image from the currently checked out version of +# MusicBrainz Solr search server (mb-solr) +# and push it to Docker Hub, tagged with versions and variants. +# +# Examples: +# - working tree at git tag v3.1.1 will push docker tags :3.1.1 :3.1 and :3 +# - working tree at git tag v3.1.1-rc.1 will push docker tag :3.1.1-rc.1 only +# - untagged working tree v3.1-1-gbfe66e3 will push docker tag 3.1.1-gbfe66e3 only +# - uncommitted/dirty working tree v3.1-dirty will push docker tag :3.1-dirty only +# +# Usage: +# $ ./push.sh -docker build -t metabrainz/solr . -docker push metabrainz/solr \ No newline at end of file +set -e -u + +image_name='metabrainz/mb-solr' + +cd "$(dirname "${BASH_SOURCE[0]}")/" + +vcs_ref=`git describe --always --broken --dirty --tags` +version=${vcs_ref#v} + +# enforce version format major.minor.patch if possible +if [[ $version =~ ^[0-9]+$ ]]; then + version="${version}.0.0" + echo "$0: appended .0.0 to version" +elif [[ $version =~ ^[0-9]+\.[0-9]+$ ]]; then + version="${version}.0" + echo "$0: appended .0 to version" +fi + +# add aliases if version is of format major.minor.patch +if [[ $version =~ ^([0-9]+)\.([0-9]+)\.[0-9]\+$ ]]; then + major=${BASH_REMATCH[1]} + minor=${BASH_REMATCH[2]} + version_aliases=( "${major}.${minor}" "${major}" ) + echo "$0: building version '$version' with aliases:" + for version_alias in ${version_aliases[@]}; do + echo "$0: - '$version_alias'" + done +else + version_aliases=() + echo "$0: building version '$version' without alias" +fi + +tag=${version} +tag_aliases=${version_aliases[@]} +timestamp=`date -u +"%Y-%m-%dT%H:%M:%SZ"` + +docker build \ + --build-arg MB_SOLR_VERSION=${version} \ + --build-arg BUILD_DATE=${timestamp} \ + --build-arg VCS_REF=${vcs_ref} \ + --tag ${image_name}:${tag} . \ + | tee ./"build-${version}-at-${timestamp}.log" + +docker push ${image_name}:${tag} + +for tag_alias in ${tag_aliases[@]}; do + docker tag ${image_name}:${tag} metabrainz/mb-solr:${tag_alias} + docker push ${image_name}:${tag_alias} +done