Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Deployment to gce for continuous integration - #607

Merged
liamsi merged 34 commits into
google:masterfrom
liamsi:kubernetes
Jun 20, 2017
Merged

liamsi merged 34 commits into
google:masterfrom
liamsi:kubernetes

Conversation

@liamsi

@liamsi liamsi commented Jun 12, 2017 •

Copy link
Copy Markdown
Contributor

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:

  1. Builds all docker images
  2. cleans up the default namespace in a particular gcloud project (delete all services, pods/deployments)
  3. pushes all trillian images to the project's container registry
  4. Starts a trillian deployment on gce
  5. pushes all keytransparency docker images to gcloud
  6. creates a log-/map-tree and sets the IDs in the keytransparency kubernetes file as environment vars
  7. runs keytransparency in gce using kubernetes

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

@liamsi liamsi added the WIP label Jun 12, 2017
@codecov-io

codecov-io commented Jun 12, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #607 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #607   +/-   ##
=======================================
  Coverage   56.76%   56.76%           
=======================================
  Files          35       35           
  Lines        2489     2489           
=======================================
  Hits         1413     1413           
  Misses        787      787           
  Partials      289      289

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 524573a...a5e8424. Read the comment docs.

@liamsi liamsi changed the title CI Deployment to gce for continuous integration Jun 15, 2017
@liamsi liamsi removed the WIP label Jun 15, 2017
@liamsi
liamsi requested review from cesarghali and gdbelvin June 15, 2017 14:46
@liamsi liamsi mentioned this pull request Jun 16, 2017
@liamsi
liamsi requested review from RJPercival and removed request for cesarghali June 16, 2017 12:54
Comment thread .travis.yml Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split the ENV variables onto separate lines if possible

@liamsi liamsi Jun 19, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread .travis.yml

dist: trusty
sudo: false
sudo: required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker build needs the docker daemon to be running. Unfortunately, it looks like we can not do without sudo: required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .travis.yml Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try using the travis apt addon to install the latest version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to using pip now which is less hacky (apt doesn't work for docker-compose).

Comment thread .travis.yml Outdated

after_success:
- bash <(curl -s https://codecov.io/bash)
# The last two commands are only needed for the deploy step (which will only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only needed in the deploy step, could it moved to the deploy step?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread .travis.yml Outdated
- 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install via apt addon

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're deleting the code behind verbose, I think... leave this as 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread .travis.yml Outdated
# 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pick a more descriptive name for the credential file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to: client_secret-and-service_key.tar.gz

Comment thread docker-compose.yml
DB_USER: test
DB_PASSWORD: zaphod
GOOGLE_APPLICATION_CREDENTIALS: /genfiles/service_key.json
KEY: /kt/server.key

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave these. It's better to have them explicitly set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@gdbelvin gdbelvin Jun 19, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transparent-keyserver should be keytransparency or key-transparency

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@liamsi liamsi Jun 19, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can name and value be put on the same line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 gdbelvin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start by cleaning up the travis config

@liamsi

liamsi commented Jun 19, 2017 •

Copy link
Copy Markdown
Contributor Author

All comments addressed: PTAL

@liamsi
liamsi force-pushed the kubernetes branch 2 times, most recently from ceb140f to 7483212 Compare June 19, 2017 14:45
@liamsi
liamsi requested review from cesarghali and gdbelvin and removed request for cesarghali June 19, 2017 21:38
Comment thread .travis.yml Outdated
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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be ./scripts/deploy.sh ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread .travis.yml Outdated
- 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


ENV MIN_SIGN_PERIOD=5s \
MAX_SIGN_PERIOD=1d
MAX_SIGN_PERIOD=24h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Comment thread cmd/keytransparency-signer/Dockerfile Outdated

ADD . /go/src/github.com/google/keytransparency
ADD trillian/testdata/* /trillian/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the newline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread kubernetes/README.md Outdated
[Google Compute Engine](https://cloud.google.com/sdk/gcloud/), run the following
command to create, upload, and run all containers:
```
cd scripts && ./deploy.sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove the cd?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,6 @@
FROM mysql:5.7

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about moving these files to
deploy/mysql-trillian
deploy/kubernetes

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread scripts/deploy.sh Outdated
################################################################################
# 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 #

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we it's assumption to be called from the root directory
$GOPATH/src/github.com/google/keytransparency ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread .gitignore Outdated
genfiles/*
.keytransparency-scts.dat
.keystore
credentials.tar.gz

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update filename

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread scripts/deploy.sh Outdated
# 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 ../..

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread scripts/deploy.sh Outdated
"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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If docker-compose tags things we might not need to do this here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (docker-compose now tags with us.gcr.io/key-transparency/)

Comment thread scripts/deploy.sh
kubectl apply -f ../kubernetes/keytransparency-deployment.yml
}

function initGcloud()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread scripts/deploy.sh
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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like docker-compose is supported by gcloud.

Comment thread scripts/deploy.sh
done
}

function pushKTImgs()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have a separate push command for KT?
Is it possible to just push everything together?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/deploy.sh
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 )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is localhost going to be a problem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@liamsi

liamsi commented Jun 20, 2017

Copy link
Copy Markdown
Contributor Author

Adressed all comments, and tested the deploy script locally. PTAL

@gdbelvin gdbelvin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@liamsi
liamsi merged commit 9c324f6 into google:master Jun 20, 2017
This was referenced Jun 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

max-period=1d is not an acceptable duration Continuous Integration Server

3 participants