automigrate when using compose file

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
David Lawrence 2016-02-03 11:25:38 -08:00
parent 6442640718
commit 3cf25b9bbb
8 changed files with 53 additions and 36 deletions

View File

@ -2,23 +2,28 @@ notaryserver:
build: .
dockerfile: server.Dockerfile
links:
- notarymysql
- notarysigner
ports:
- "8080"
- "4443:4443"
- notarymysql
- notarysigner
environment:
- SERVICE_NAME=notary
command: -config=fixtures/server-config.json
notarysigner:
- SERVICE_NAME=notaryserver
volumes:
- /dev/bus/usb/003/010:/dev/bus/usb/002/010
- /var/run/pcscd/pcscd.comm:/var/run/pcscd/pcscd.comm
- ./migrations:/migrations
ports:
- "8080"
- "4443:4443"
entrypoint: /bin/bash
command: -c "/migrations/migrate.sh; notary-server -config=fixtures/server-config.json"
notarysigner:
build: .
dockerfile: signer.Dockerfile
links:
- notarymysql
command: -config=fixtures/signer-config.json
- notarymysql
environment:
- SERVICE_NAME=notarysigner
volumes:
- ./migrations:/migrations
entrypoint: /bin/bash
command: -c "/migrations/migrate.sh; notary-signer -config=fixtures/signer-config.json"
notarymysql:
volumes:
- ./notarymysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d

20
migrations/migrate.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
case $SERVICE_NAME in
notaryserver)
# have to poll for DB to come up
until migrate -path=/migrations/server/mysql -url="mysql://server@tcp(notarymysql:3306)/notaryserver" up
do
sleep 1
done
echo "notaryserver database migrated to latest version"
;;
notarysigner)
# have to poll for DB to come up
until migrate -path=/migrations/signer/mysql -url="mysql://signer@tcp(notarymysql:3306)/notarysigner" up
do
sleep 1
done
echo "notarysigner database migrated to latest version"
;;
esac

View File

@ -1,3 +0,0 @@
DROP TABLE `timestamp_keys`;
DROP TABLE `tuf_files`;

View File

@ -1 +0,0 @@
ALTER TABLE `timestamp_keys` DROP KEY `gun_role`, DROP COLUMN `role`, ADD UNIQUE KEY `gun` (`gun`);

View File

@ -1 +0,0 @@
ALTER TABLE `tuf_files` DROP INDEX `sha256`, DROP COLUMN `sha256`;

View File

@ -1 +0,0 @@
DROP TABLE `private_keys`;

View File

@ -1,4 +1,5 @@
FROM golang:1.5.1
FROM golang:1.5.3
MAINTAINER Diogo Monica "diogo@docker.com"
RUN apt-get update && apt-get install -y \
libltdl-dev \
@ -7,13 +8,20 @@ RUN apt-get update && apt-get install -y \
EXPOSE 4443
# Install DB migration tool
RUN go get github.com/mattes/migrate
ENV NOTARYPKG github.com/docker/notary
ENV GOPATH /go/src/${NOTARYPKG}/Godeps/_workspace:$GOPATH
# Copy the local repo to the expected go path
COPY . /go/src/github.com/docker/notary
WORKDIR /go/src/${NOTARYPKG}
# 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`" \

View File

@ -1,29 +1,20 @@
FROM dockersecurity/golang-softhsm2
FROM golang:1.5.3
MAINTAINER Diogo Monica "diogo@docker.com"
# CHANGE-ME: Default values for SoftHSM2 PIN and SOPIN, used to initialize the first token
ENV NOTARY_SIGNER_PIN="1234"
ENV SOPIN="1234"
ENV LIBDIR="/usr/local/lib/softhsm/"
ENV NOTARY_SIGNER_DEFAULT_ALIAS="timestamp_1"
ENV NOTARY_SIGNER_TIMESTAMP_1="testpassword"
# Install openSC and dependencies
RUN apt-get update && apt-get install -y \
libltdl-dev \
libpcsclite-dev \
opensc \
usbutils \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# Initialize the SoftHSM2 token on slod 0, using PIN and SOPIN varaibles
RUN softhsm2-util --init-token --slot 0 --label "test_token" --pin $NOTARY_SIGNER_PIN --so-pin $SOPIN
EXPOSE 4444
# Install DB migration tool
RUN go get github.com/mattes/migrate
ENV NOTARYPKG github.com/docker/notary
ENV GOPATH /go/src/${NOTARYPKG}/Godeps/_workspace:$GOPATH
EXPOSE 4444
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
@ -36,6 +27,5 @@ RUN go install \
-ldflags "-w -X ${NOTARYPKG}/version.GitCommit=`git rev-parse --short HEAD` -X ${NOTARYPKG}/version.NotaryVersion=`cat NOTARY_VERSION`" \
${NOTARYPKG}/cmd/notary-signer
ENTRYPOINT [ "notary-signer" ]
CMD [ "-config=fixtures/signer-config-local.json" ]