Jetbrain Space Automation how to deploy an image to AWS EKS (Kubernetes)?

386 views Asked by At

I am trying to be able to deploy an image from a space repository to AWS EKS. So far I managed to successfully save my docker image to Space. But I stuck at finding a way to upload my image to my cluster.

So far I've created the following to save my docker image to the registy. Does someone know how I could push this towards AWS EKS? Thank you in advance for taking the time help me!

job("Build Image and save to registry") {
    startOn {
        gitPush {
            branchFilter {
                +"refs/heads/main"
            }
        }
    }
    
    docker {
        resources {
            cpu = 512
            memory = 1024
        }

        build {
            context = "."
            file = "Dockerfile"
        }
    
        push("<my-private>.registry.jetbrains.space/p/repo/repo/image:latest")
    }
}
1

There are 1 answers

0
Joffrey On

EDIT: my bad, it turns out I misunderstood the question!

I'm not an AWS guru, but to deploy to a Kubernetes cluster, I believe you would just need an extra step calling kubectl apply -f your-service.yml or something like that.


It is not possible out-of-the-box to push to private registries via the docker (now kaniko) top-level DSL, but this DSL is rather legacy.

Instead, use the dockerBuildPush DSL in a host step (instead of a docker/kaniko step).

One way to login to the private registry is to provide the credentials as secrets to the job (add the secrets in the project settings first) and do a docker login command in a shellScript block before dockerBuildPush:

job("Build Image and save to registry") {
    startOn {
        gitPush {
            anyBranchMatching {
                +"main"
            }
        }
    }
    
    host {
        env["REGISTRY_USER"] = "{{ project:registry_user }}"
        env["REGISTRY_PASS"] = "{{ project:registry_pass }}"
        env["REGISTRY_URL"] = "{{ project:registry_url }}"
        shellScript {
            content = "docker login -u \$REGISTRY_USER -p \$REGISTRY_PASS \$REGISTRY_URL"
        }
        dockerBuildPush {
            tags {
                +"<my-private>.registry.jetbrains.space/p/repo/repo/image:latest"
            }
        }
    }
}

As of June 2023, you can now also use the dockerRegistryConnections DSL (but it's not available in the Free plan). In your project settings, you need to go to Docker Registry Connections tab, and add credentials there, and give them a key for reference, e.g. "my-private-registry". Then you can simply add a dockerRegistryConnections block with a reference to your key, and the worker will login before the step and logout after the step, without the need for manipulating secrets:

job("Build Image and save to registry") {
    startOn {
        gitPush {
            anyBranchMatching {
                +"main"
            }
        }
    }
    
    host {
        dockerRegistryConnections {
            +"my-private-registry"
        }
        dockerBuildPush {
            tags {
                +"<my-private>.registry.jetbrains.space/p/repo/repo/image:latest"
            }
        }
    }
}

See the documentation for more info.