Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GCP GKE support #209

Merged
merged 6 commits into from
Jan 21, 2019
Merged

Add GCP GKE support #209

merged 6 commits into from
Jan 21, 2019

Conversation

mastoj
Copy link
Contributor

@mastoj mastoj commented Dec 30, 2018

Fixes: #208
Docs: SAFE-Stack/docs#91

Adds support for kubernetes in general and Google Cloud Kubernetes Engine in particular.

  • Create docker tag from git sha
  • Publish docker image to google container registry
  • Auth with kubernetes cluster
  • Deploy as new app
  • Update existing app

The PR assumes two tools are pre-installed:

  • gcloud - cli tool to interact with gcp
  • kubectl - cli tool to interact with kubernetes

Given the above is installed and that you have a gcp project and gke cluster running. You can test this out by running:

dotnet new SAFE --deploy gcp-kubernetes
fake run build.fsx -t Deploy

Again, this serves as a way to getting started and will suffice for smaller apps.

@mastoj
Copy link
Contributor Author

mastoj commented Dec 30, 2018

This has only been tested on OSX. No Windows machine available at the moment. I think it could work on Windows as well since I'm not using any shell commands.

@mastoj
Copy link
Contributor Author

mastoj commented Jan 2, 2019

Updated PR to include the option to set the kubernetes cluster using -e SAFE_CLUSTER. If not set it will default to a kubernetes cluster named "safe-cluster".

Also, the FAKE tasks are structured so that the kubernetes specific ones can be used for any kubernetes cluster as long as kubectl is configured correctly.

@mastoj mastoj mentioned this pull request Jan 2, 2019
@@ -64,4 +64,7 @@ group Build
nuget Fake.IO.Zip
github CompositionalIT/fshelpers src/FsHelpers/ArmHelper/ArmHelper.fs
//#endif
//#if (deploy == "gcp-kubernetes")
nuget Fake.Tools.Git
Copy link
Member

Choose a reason for hiding this comment

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

we'll need to add new case to paket lock generation for this - I can add that afterwards

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, since I have no clue about how that part works.

Target.create "Publish" (fun _ ->
let dockerTag = createDockerTag dockerImageName
let pushArgs = sprintf "push %s" dockerTag
runTool "docker" pushArgs "."
Copy link
Member

Choose a reason for hiding this comment

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

unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication <- should be probably reflected in docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add, I guess I had already done that in my environment.

@mastoj
Copy link
Contributor Author

mastoj commented Jan 11, 2019

It shouldn't be too hard to add kubernetes support for azure and aws after this I guess. Not sure how that works on those platforms, but I imagine it is similar.

@theimowski
Copy link
Member

Can you rebase on master?

@mastoj
Copy link
Contributor Author

mastoj commented Jan 15, 2019 via email

@@ -19,6 +19,10 @@ open Cit.Helpers.Arm
open Cit.Helpers.Arm.Parameters
open Microsoft.Azure.Management.ResourceManager.Fluent.Core
//#endif
//#if (deploy == "gcp-kubernetes")
open System.Text.RegularExpressions
open Fake.Tools.Git
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking - is it really crucial to employ Git here? Can we find a different way to create a docker tag? Adding this dependency has 2 main drawbacks:

  • it implies the user needs to actually create git repo and commit before testing out the deployment
  • makes template a bit harder to maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be solved with a version variable. The reason I added it is because I see it as a good example of how to version your docker container based on your git sha, which does make some things around versioning slightly simpler in some scenarios, and also deterministic.

If it adds a lot of complexity I can, of course, figure something else out. What do you think based on motivation to why I added it in the first place @theimowski?

Copy link
Member

Choose a reason for hiding this comment

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

Yes I totally agree it's a go-to solution for deterministic tagging.
However in case of a template it's more steps for a user to try out functionality, and we strive to make the template as easy to use as possible and with minimal steps to deploy.

Can you push to Google Container Registry a docker image without tag (projectId/projectName instead of projectId/projectName:tag)?
If so maybe this could be the easiest way to start with. Otherwise - what would a "version variable" look like?

Content/build.fsx Outdated Show resolved Hide resolved
@mastoj
Copy link
Contributor Author

mastoj commented Jan 17, 2019

Rebased on master now.

@mastoj
Copy link
Contributor Author

mastoj commented Jan 17, 2019 via email

@theimowski
Copy link
Member

I can make it as simple as possible and instead write something
about the more advanced tagging in the docs.

Please do - that would be my preference.

nothing happen since the tag is still the same

Is it really the case? I mean if you push the image with the same tag, doesn't it override the existing one in registry? I think that is what happens in case of Docker Hub for example.

@mastoj
Copy link
Contributor Author

mastoj commented Jan 17, 2019 via email

@theimowski
Copy link
Member

If it doesn't, let's just mention that in docs. For the template what really matters is the first-time deploy.

@mastoj
Copy link
Contributor Author

mastoj commented Jan 18, 2019

I've applied the changes and also verified that it indeed work the way I said. I'll update the docs later this weekend to reflect the changes and also with the suggestion on how to use the git sha for versioning.

@theimowski
Copy link
Member

Thanks for that. I'm aware we might not be contributing to "best practices" here, however IMO it's crucial to find a right balance between simplicity and correctness for this template.

@theimowski theimowski merged commit 016565a into SAFE-Stack:master Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants