Using Pulumi to Deploy helloworld Docker Images to Google Kubernetes Engine (GKE)

I am attempting to deploy a hello world container in Kubernetes using Pulumi and GCP.

Essentially, I want to deploy this local helloworld container into an existing k8s cluster on GCP following the tutorial found here.

Deploying local images is showcased in this other example, but I encounter an error by adding registry information:

Property 'repositoryUrl' does not exist on type 'Promise<GetRegistryRepositoryResult>'.

const registry = gcp.container.getRegistryRepository();
// Build a Docker image from a local Dockerfile context in the
// './mydockerimg' directory, and push it to the registry.
//const registry = gcp.container.getRegistryRepository();
const customImage = "mydockerimg";
const appImage = new docker.Image(customImage, {
//    imageName: pulumi.interpolate`${registry.repositoryUrl}/${customImage}:v1.0.0`,
    imageName: "mydockerimg",
    build: {
        context: `./${customImage}`,
    },
});
// Create a k8s provider.
// NOT NEEDED
// Create a Deployment of the built container.
const appLabels_helloworld = { app: customImage };
const appDeployment = new k8s.apps.v1.Deployment("app", {
    spec: {
        selector: { matchLabels: appLabels_helloworld },
        replicas: 1,
        template: {
            metadata: { labels: appLabels_helloworld },
            spec: {
                containers: [{
                    name: customImage,
                    image: appImage.imageName,
                    ports: [{name: "http", containerPort: 80}],
                }],
            }
        },
    }
}, { provider: clusterProvider });

By just using

imageName: "mydockerimg",
without a registry, Pulumi accepts the upgrade, but then I face a docker push error:

error: Error: ' docker push mydockerimg:4aff09801cccc271a8182a3eb3bc46a25764fdbb5332230c6aa707e3b90c4d4e' failed with exit code 1
    The push refers to repository [docker.io/library/mydockerimg]

Any guidance would be appreciated.


UPDATE: After implementing Yaron Idan's suggestion below, running pulumi up works, but still cannot export the app due to being unable to push.

const gcrLocation = registry.then(registry => registry.repositoryUrl);
...
imageName: pulumi.interpolate`${gcrLocation}/${customImage}:v1.0.0`,
...
export const appDeploymentName = appDeployment.metadata.apply(m => m.name);

The encountered error:

 Error: ' docker push gcr.io/XXX' failed with exit code 1

Further investigation has led me to encounter error: name unknown: Buckets(projectID,artifacts.napoleongamesassignment.appspot.com)

after trying to

docker push gcr.io/myprojectID/myrstudio:latest
,

I have posted another question regarding this issue.

Answer №1

Seems like the issue lies in extracting the repository URL from the promise instead of its resolution.
Referencing this example from the Pulumi documentation, it suggests modifying your code snippet from

imageName: pulumi.interpolate`${registry.repositoryUrl}/${customImage}:v1.0.0`,

to

imageName: pulumi.interpolate`${registry.then(foo => foo.repositoryUrl)}/${customImage}:v1.0.0`,

This adjustment should provide you with the desired outcome.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The functionality of ItemSliding appears to be disabled when used in combination with

Could you please help me figure out why the Me button is not visible? I implemented the ItemSliding component. Here is the link to the stackblitz project. The issue is within the home folder. I am trying to create a list like the one below: UI https:// ...

Why is it that a static variable cannot be accessed using the `this` keyword in a static method when the static method is called in any route's controller in NODEJS?

Is it possible to access static variables in a static method using the 'this' keyword? The answer is yes, but there seems to be an issue when passing that static method in any route. The 'this' keyword refers to the class, yet its value ...

Creating a supplementary container to transfer files between a device external to the Kubernetes cluster

Excuse my lack of expertise, but I have a question. If I am utilizing a docker image that relies on a folder within the host system to function, where should this folder be placed in the kubernetes cluster? While I can easily navigate this setup with Docke ...

What is the best way to determine if a user is currently in a voice channel using discord.js?

Is there a way for me to determine if a user is currently linked to a voice channel? I am trying to implement a command that allows me to remove a user from a voice channel, and here is how I am attempting to check: const user: any = interaction.options.ge ...

A Guide to Handling Errors while Converting a Map to a Promise in Typescript

I am attempting to capture errors if any of the asynchronous code within my map function fails. It seems to enter the error block but does not log anything, as the error variable remains null. Is there an alternative method for handling errors within map ...

Exploring the potential of React with Typescript: Learn how to maximize

Having some difficulties working with Amplitude in a React and Typescript environment. Anyone else experiencing this? What is the proper way to import Amplitude and initialize it correctly? When attempting to use import amp from 'amplitude-js'; ...

The TypeScript in the React-Native app is lacking certain properties compared to the expected type

I recently integrated the https://github.com/react-native-community/react-native-modal library into my project and now I need to create a wrapper Modal class. Initially, I set up an Interface that extends multiple interfaces from both react-native and reac ...

delayed updating of property not visible in angular 10 immediately

I needed to hide a div based on a condition, so I decided to use the hidden property like below: <div [hidden]="isControlDisplayed()?false:true"> The isControlDisplayed() method determines whether to show or hide the div based on the value ...

Exploring abstract classes for diverse implementation strategies?

Consider the following scenario: export abstract class Button { constructor(public config: IButton) {} abstract click(); } Now, we have a concrete class: class ButtonShowMap extends Button { private isShow = false; constructor(public config: IBu ...

Displaying a component inside a different component

I'm attempting to display components inside another component, but even when I try to include div elements within the component, they don't show up. const DisplayComponent = () => { return ( <div> <DisplayContent ...

Different types of subscriptions for forkJoin observable

I am currently making two API requests with typed responses and combining them using the Observable.forkJoin method. My goal is to store each of the results in separate typed variables. var observableOrganization: Observable<Organization> = this.get ...

Best Practices for Implementing Redux Prop Types in Typescript React Components to Eliminate TypeScript Warnings

Suppose you have a React component: interface Chat { someId: string; } export const Chat = (props: Chat) => {} and someId is defined in your mapStateToProps: function mapStateToProps(state: State) { return { someId: state.someId || '' ...

Upon initialization, navigate to the specified location in the route by scrolling

My page has various components stacked one after the other, such as: <about></about> <contact></contact> I am utilizing the ng2-page-scroll to smoothly scroll to a particular section when a navigation link is clicked. However, I a ...

Utilizing Docker to dynamically set VueJS environment variables during runtime

I'm currently facing an issue with dockerizing my Vue app for use in a Kubernetes/Rancher environment. My goal is to set environmental variables in Rancher, such as the API base url, but I'm unsure of how to accomplish this. Below is my Dockerf ...

Utilizing Interface Merging: Determining the Appropriate Instance Type for Field Types

I am in need of writing a definition file for an external library. I have augmented a class using interface merging and there are situations where a field of the library class is of the same type as the instance itself. Here is a snippet of demo code: // ...

Utilizing .js file alongside declaration files .d.ts in Angular: A guide

I am facing an issue with my Angular 7 app where I need to include some typed JS constants from outside of the project. These constants are essential for the AngularJS app and need to be kept in a separate js file. I have defined a new path in the tsconfig ...

Ways to send a message from a chrome extension to a webpage and patiently await a reply

Currently, I'm exploring ways to send messages from a Chrome extension to a page view and wait for a response. Here's what I've tried so far: In the extension's content_script.js: window.addEventListener('message', function(e ...

The TypeScript compiler is tolerant when a subclass inherits a mixin abstract class without implementing all its getters

Update: In response to the feedback from @artur-grzesiak below, we have made changes to the playground to simplify it. We removed a poorly named interface method and now expect the compiler to throw an error for the unimplemented getInterface. However, the ...

The component is no longer able to locate the imported element when it is being shared

Recently, I imported a component into the shared module in order to use it across 2 different modules. However, upon recompiling the app, an error message appeared stating that the jodit-editor, which is utilized by the shared component, is not recognized ...

Utilizing Variables in TypeScript to Enhance String Literal Types

Here are my codes: export const LOAD_USERS = 'LOAD_USERS'; export const CREATE_USER = 'CREATE_USER'; export interface ACTION { type: string, payload: any } I am trying to limit the possible values for ACTION.type to either 'L ...