From a021d16392aeafe324ef070cff7818e1c6b3fb4b Mon Sep 17 00:00:00 2001 From: Ying Li Date: Thu, 17 Mar 2016 15:12:05 -0700 Subject: [PATCH] Convert the server and signer to use the alpine image and to remove apks after build Signed-off-by: Ying Li --- development.yml | 4 ++-- docker-compose.yml | 4 ++-- migrations/migrate.sh | 12 ++++++------ server.Dockerfile | 15 ++++++--------- signer.Dockerfile | 20 +++++++++----------- 5 files changed, 25 insertions(+), 30 deletions(-) diff --git a/development.yml b/development.yml index 243087a328..3aada92e5d 100644 --- a/development.yml +++ b/development.yml @@ -7,7 +7,7 @@ server: - signer:notarysigner environment: - SERVICE_NAME=notary_server - entrypoint: /bin/bash + entrypoint: /usr/bin/env sh command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json" signer: build: . @@ -16,7 +16,7 @@ signer: - mysql environment: - SERVICE_NAME=notary_signer - entrypoint: /bin/bash + entrypoint: /usr/bin/env sh command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json" mysql: volumes: diff --git a/docker-compose.yml b/docker-compose.yml index 4f8705f384..00be689c2e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ server: ports: - "8080" - "4443:4443" - entrypoint: /bin/bash + entrypoint: /usr/bin/env sh command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json" signer: build: . @@ -19,7 +19,7 @@ signer: - mysql environment: - SERVICE_NAME=notary_signer - entrypoint: /bin/bash + entrypoint: /usr/bin/env sh command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json" mysql: volumes: diff --git a/migrations/migrate.sh b/migrations/migrate.sh index adb4c3db11..866a1e19bd 100755 --- a/migrations/migrate.sh +++ b/migrations/migrate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env sh # When run in the docker containers, the working directory # is the root of the repo. @@ -10,8 +10,8 @@ case $SERVICE_NAME in # have to poll for DB to come up until migrate -path=migrations/server/mysql -url="mysql://server@tcp(mysql:3306)/notaryserver" version > /dev/null do - ((iter++)) - if (( iter > 30 )); then + iter=$(( iter+1 )) + if [[ $iter -gt 30 ]]; then echo "notaryserver database failed to come up within 30 seconds" exit 1; fi @@ -35,8 +35,8 @@ case $SERVICE_NAME in # have to poll for DB to come up until migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version > /dev/null do - ((iter++)) - if (( iter > 30 )); then + iter=$(( iter+1 )) + if [[ $iter -gt 30 ]]; then echo "notarysigner database failed to come up within 30 seconds" exit 1; fi @@ -44,7 +44,7 @@ case $SERVICE_NAME in sleep 1 done pre=$(migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version) - if migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" up ; then + if migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" up ; then post=$(migrate -path=migrations/signer/mysql -url="mysql://signer@tcp(mysql:3306)/notarysigner" version) if [ "$pre" != "$post" ]; then echo "notarysigner database migrated to latest version" diff --git a/server.Dockerfile b/server.Dockerfile index 0966cea232..8b60e467c6 100644 --- a/server.Dockerfile +++ b/server.Dockerfile @@ -1,12 +1,7 @@ -FROM golang:1.6.0 +FROM golang:1.6.0-alpine MAINTAINER David Lawrence "david.lawrence@docker.com" -RUN apt-get update && apt-get install -y \ - libltdl-dev \ - --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* - -EXPOSE 4443 +RUN apk add --update git gcc libc-dev && rm -rf /var/cache/apk/* # Install DB migration tool RUN go get github.com/mattes/migrate @@ -16,13 +11,15 @@ ENV NOTARYPKG github.com/docker/notary # Copy the local repo to the expected go path COPY . /go/src/github.com/docker/notary -WORKDIR /go/src/${NOTARYPKG} +WORKDIR /go/src/github.com/docker/notary + +EXPOSE 4443 # Install notary-server RUN go install \ -tags pkcs11 \ -ldflags "-w -X ${NOTARYPKG}/version.GitCommit=`git rev-parse --short HEAD` -X ${NOTARYPKG}/version.NotaryVersion=`cat NOTARY_VERSION`" \ - ${NOTARYPKG}/cmd/notary-server + ${NOTARYPKG}/cmd/notary-server && apk del git gcc libc-dev ENTRYPOINT [ "notary-server" ] CMD [ "-config=fixtures/server-config-local.json" ] diff --git a/signer.Dockerfile b/signer.Dockerfile index 846e30e56f..6887095c6f 100644 --- a/signer.Dockerfile +++ b/signer.Dockerfile @@ -1,30 +1,28 @@ -FROM golang:1.6.0 +FROM golang:1.6.0-alpine MAINTAINER David Lawrence "david.lawrence@docker.com" -RUN apt-get update && apt-get install -y \ - libltdl-dev \ - --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* - -EXPOSE 4444 +RUN apk add --update git gcc libc-dev && rm -rf /var/cache/apk/* # Install DB migration tool RUN go get github.com/mattes/migrate ENV NOTARYPKG github.com/docker/notary -ENV NOTARY_SIGNER_DEFAULT_ALIAS="timestamp_1" -ENV NOTARY_SIGNER_TIMESTAMP_1="testpassword" # Copy the local repo to the expected go path COPY . /go/src/github.com/docker/notary -WORKDIR /go/src/${NOTARYPKG} +WORKDIR /go/src/github.com/docker/notary + +ENV NOTARY_SIGNER_DEFAULT_ALIAS="timestamp_1" +ENV NOTARY_SIGNER_TIMESTAMP_1="testpassword" + +EXPOSE 4444 # Install notary-signer RUN go install \ -tags pkcs11 \ -ldflags "-w -X ${NOTARYPKG}/version.GitCommit=`git rev-parse --short HEAD` -X ${NOTARYPKG}/version.NotaryVersion=`cat NOTARY_VERSION`" \ - ${NOTARYPKG}/cmd/notary-signer + ${NOTARYPKG}/cmd/notary-signer && apk del git gcc libc-dev ENTRYPOINT [ "notary-signer" ] CMD [ "-config=fixtures/signer-config-local.json" ]