Repository navigation
Deployment to gce for continuous integration - #607
Conversation
Codecov Report
@@ Coverage Diff @@
## master #607 +/- ##
=======================================
Coverage 56.76% 56.76%
=======================================
Files 35 35
Lines 2489 2489
=======================================
Hits 1413 1413
Misses 787 787
Partials 289 289Continue to review full report at Codecov.
|
| directories: | ||
| - "$HOME/google-cloud-sdk/" | ||
| env: | ||
| - DOCKER_COMPOSE_VERSION="1.13.0" PATH=$PATH:${HOME}/google-cloud-sdk/bin CLOUDSDK_CORE_DISABLE_PROMPTS=1 PROJECT_NAME=transparent-keyserver |
There was a problem hiding this comment.
Split the ENV variables onto separate lines if possible
There was a problem hiding this comment.
If you split them in several lines/items one build will be triggered per line: https://docs.travis-ci.com/user/environment-variables/#Defining-public-variables-in-.travis.yml
But it seems
env:
global:
# separate line per VAR
does what we want. Will do. done
|
|
||
| dist: trusty | ||
| sudo: false | ||
| sudo: required |
There was a problem hiding this comment.
From the travis docs, it looks like we can set sudo to false and just get the docker binaries.
Docker is installed. We use the official Docker apt repository, so you can easily install another version with apt if needed. When sudo: required is specified, Docker is installed as a service. When sudo: false is specified, the Docker binaries are available for local use.
There was a problem hiding this comment.
docker build needs the docker daemon to be running. Unfortunately, it looks like we can not do without sudo: required.
There was a problem hiding this comment.
The only viable alternative I've found: Instead of running docker-compose build on travis (and therefore needing sudo to run the daemon), we could get rid of docker-compose, run only docker build instead and do this in gcloud instead of travis with gcloud docker -- build <image-to-be-build>. Se: https://cloud.google.com/sdk/gcloud/reference/docker
This could be faster, too.
| env: | ||
| - DOCKER_COMPOSE_VERSION="1.13.0" PATH=$PATH:${HOME}/google-cloud-sdk/bin CLOUDSDK_CORE_DISABLE_PROMPTS=1 PROJECT_NAME=transparent-keyserver | ||
| before_install: | ||
| - sudo rm /usr/local/bin/docker-compose |
There was a problem hiding this comment.
Could you try using the travis apt addon to install the latest version?
There was a problem hiding this comment.
Switched to using pip now which is less hacky (apt doesn't work for docker-compose).
|
|
||
| after_success: | ||
| - bash <(curl -s https://codecov.io/bash) | ||
| # The last two commands are only needed for the deploy step (which will only |
There was a problem hiding this comment.
If this is only needed in the deploy step, could it moved to the deploy step?
| - openssl aes-256-cbc -K $encrypted_a1eb99cfc21e_key -iv $encrypted_a1eb99cfc21e_iv -in credentials.tar.gz.enc -out credentials.tar.gz -d | ||
| - if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; curl https://sdk.cloud.google.com | bash; fi | ||
| # needed for envsubst command used in deploy script: | ||
| - sudo apt-get install gettext |
There was a problem hiding this comment.
Switched to sed as you suggested (thanks).
| ENV LOG_ID=0 \ | ||
| LOG_URL=localhost:8090 | ||
| ENV GOOGLE_APPLICATION_CREDENTIALS=genfiles/service_key.json | ||
| ENV VERBOSE=0 |
There was a problem hiding this comment.
We're deleting the code behind verbose, I think... leave this as 0
| # The last two commands are only needed for the deploy step (which will only | ||
| # run on master. The first fails on PRs from forks (but the build passes), the | ||
| # 2nd only does sth. if the cache is empty. | ||
| - openssl aes-256-cbc -K $encrypted_a1eb99cfc21e_key -iv $encrypted_a1eb99cfc21e_iv -in credentials.tar.gz.enc -out credentials.tar.gz -d |
There was a problem hiding this comment.
Please pick a more descriptive name for the credential file
There was a problem hiding this comment.
Changed to: client_secret-and-service_key.tar.gz
| DB_USER: test | ||
| DB_PASSWORD: zaphod | ||
| GOOGLE_APPLICATION_CREDENTIALS: /genfiles/service_key.json | ||
| KEY: /kt/server.key |
There was a problem hiding this comment.
leave these. It's better to have them explicitly set
There was a problem hiding this comment.
The trillian-log-signer doesn't need them. Copied from its Dockerfile:
/go/bin/trillian_log_signer \
--mysql_uri="${DB_USER}:${DB_PASSWORD}@tcp(${DB_HOST})/${DB_DATABASE}" \
--http_endpoint="$HOST:$HTTP_PORT" \
--sequencer_guard_window="$SEQUENCER_GUARD_WINDOW" \
--force_master="$FORCE_MASTER" \
--alsologtostderr
| spec: | ||
| containers: | ||
| - name: kt-server | ||
| image: us.gcr.io/transparent-keyserver/keytransparency-server |
There was a problem hiding this comment.
transparent-keyserver should be keytransparency or key-transparency
There was a problem hiding this comment.
I've created a new service-key in this project but authenticating using this key does not grant the permissions to create a repository for the container registry there. Either one of the owners need to create a key-file, download it and encrypt it after we merged this pull or you need to grant me access to do so.
| - containerPort: 8080 | ||
| name: json-grpc | ||
| env: | ||
| - name: LOG_URL |
There was a problem hiding this comment.
can name and value be put on the same line?
There was a problem hiding this comment.
This seems to be the default (as in the documentation). But I've tried:
- name: LOG_URL value: trillian-log:8090
and get an error: error: error converting YAML to JSON: yaml: line 24: mapping values are not allowed in this context
gdbelvin
left a comment
There was a problem hiding this comment.
Let's start by cleaning up the travis config
|
All comments addressed: PTAL |
ceb140f to
7483212
Compare
- update gitignore - not yet working kubernetes db deployment
comments, simplified cred. file, fix sed,
| curl https://sdk.cloud.google.com | bash; fi | ||
| - openssl aes-256-cbc -K $encrypted_a1eb99cfc21e_key -iv $encrypted_a1eb99cfc21e_iv -in service_key.tar.gz.enc -out service_key.tar.gz -d | ||
| - tar -xzf service_key.tar.gz | ||
| - (cd scripts && ./deploy.sh) |
There was a problem hiding this comment.
should this be ./scripts/deploy.sh ?
| - docker-compose --version | ||
| - if [ ! -d "$HOME/google-cloud-sdk/bin" ]; then rm -rf $HOME/google-cloud-sdk; | ||
| curl https://sdk.cloud.google.com | bash; fi | ||
| - openssl aes-256-cbc -K $encrypted_a1eb99cfc21e_key -iv $encrypted_a1eb99cfc21e_iv -in service_key.tar.gz.enc -out service_key.tar.gz -d |
There was a problem hiding this comment.
Double check that service_key.tar.gz.enc is still correct. It doesn't look like it matches with the .enc file in the PR.
Consider naming this travis_secrets.tar.gz.enc
|
|
||
| ENV MIN_SIGN_PERIOD=5s \ | ||
| MAX_SIGN_PERIOD=1d | ||
| MAX_SIGN_PERIOD=24h |
|
|
||
| ADD . /go/src/github.com/google/keytransparency | ||
| ADD trillian/testdata/* /trillian/ | ||
|
|
| [Google Compute Engine](https://cloud.google.com/sdk/gcloud/), run the following | ||
| command to create, upload, and run all containers: | ||
| ``` | ||
| cd scripts && ./deploy.sh |
There was a problem hiding this comment.
Is it possible to remove the cd?
| @@ -0,0 +1,6 @@ | |||
| FROM mysql:5.7 | |||
There was a problem hiding this comment.
What do you think about moving these files to
deploy/mysql-trillian
deploy/kubernetes
?
| ################################################################################ | ||
| # Following assumptions are made by this script: # | ||
| # * gcloud, docker, and docker-compose is installed # | ||
| # * it is called from $GOPATH/src/github.com/google/keytransparency/scripts # |
There was a problem hiding this comment.
Could we it's assumption to be called from the root directory
$GOPATH/src/github.com/google/keytransparency ?
| genfiles/* | ||
| .keytransparency-scts.dat | ||
| .keystore | ||
| credentials.tar.gz |
| # Work around some git permission issues on linux: | ||
| chmod a+r ../../trillian/storage/mysql/storage.sql | ||
| # Create and push a fresh db image (with schema created) | ||
| docker build -t us.gcr.io/${PROJECT_NAME}/db -f ../kubernetes/mysql-trillian/Dockerfile ../.. |
There was a problem hiding this comment.
See if you can get docker-compose to do this for you.
- Set the tag
- it's ok to hardcode the project
- See if you can publish the containers
There was a problem hiding this comment.
All done besides publishing. gcloud doesn't seem to support docker-compose. What we could do though, is make docker login into gcloud: https://stackoverflow.com/a/29311300
Do you think that's safe and worth trying?
| "trillian_log_signer" "keytransparency-signer") | ||
| for DOCKER_IMAGE_NAME in "${images[@]}" | ||
| do | ||
| docker tag ${DOCKER_IMAGE_NAME} us.gcr.io/${PROJECT_NAME}/${DOCKER_IMAGE_NAME} |
There was a problem hiding this comment.
If docker-compose tags things we might not need to do this here.
There was a problem hiding this comment.
done (docker-compose now tags with us.gcr.io/key-transparency/)
| kubectl apply -f ../kubernetes/keytransparency-deployment.yml | ||
| } | ||
|
|
||
| function initGcloud() |
There was a problem hiding this comment.
| do | ||
| docker tag ${DOCKER_IMAGE_NAME} us.gcr.io/${PROJECT_NAME}/${DOCKER_IMAGE_NAME} | ||
| # Push the images as we refer to them in the kubernetes config files: | ||
| gcloud docker -- push us.gcr.io/${PROJECT_NAME}/${DOCKER_IMAGE_NAME} |
There was a problem hiding this comment.
docker-compose push?
https://docs.docker.com/compose/reference/push/
There was a problem hiding this comment.
Doesn't look like docker-compose is supported by gcloud.
| done | ||
| } | ||
|
|
||
| function pushKTImgs() |
There was a problem hiding this comment.
Do we need to have a separate push command for KT?
Is it possible to just push everything together?
There was a problem hiding this comment.
As discussed: As we need to wait for the trillian services to be up and running, we can as well spent this time doing sth. we need to do anyways.
| let COUNTER+=1 | ||
| # get the currentl trillian-map pod: | ||
| MAPSRV=$(kubectl get pods --selector=run=trillian-map -o jsonpath={.items[*].metadata.name}); | ||
| LOG_ID=$(echo 'go run $GOPATH/src/github.com/google/trillian/cmd/createtree/main.go --admin_server=localhost:8090 --pem_key_path=testdata/log-rpc-server.privkey.pem --pem_key_password="towel" --signature_algorithm=ECDSA --tree_type=LOG' | kubectl exec -i $MAPSRV -- /bin/sh ) |
There was a problem hiding this comment.
is localhost going to be a problem?
There was a problem hiding this comment.
No, the command will be run directly on the pod (at the very end: kubectl exec -i $MAPSRV -- /bin/sh
But we can change to trillian-map for consistency, if you prefer (which will resolve to the same machine as localhost).
|
Adressed all comments, and tested the deploy script locally. PTAL |
Work in progress PR created early to trigger travis (on the original repo, not my fork)Will eventually resolve #601
Added kubernetes configuration and a deploy script which:
This script can be used locally or by travis. Travis will run the script every time after pull gets merged into master.
Resolves #601
Also resolves #615