has anyone come across an error like : ``` &gt...
# general
i
has anyone come across an error like :
Copy code
> [2/2] COPY ./abc/abc_bin.jar app.jar:
    ------
    failed to compute cache key: "./abc/abc_bin.jar" not found: not found
when trying to build a docker image with Pulumi. My DockerFile (
ExampleProject/abc/DockerFile
)looks like this :
Copy code
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=./abc/abc_bin.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
My top level Bazel project is named
ExampleProject
under which I have
abc
as follows :
ExampleProject/abc
. When I run
bazel build //abc/...
from
ExampleProject
it creates a new directory called
/ExampleProject/bazel-bin/abc
which has all the jars including
abc_bin.jar
a
what is the context of your DockerBuild in pulumi code?
i
My Pulumi code for building image is as follows:
Copy code
const repo2 = new aws.ecr.Repository("ecr_trial");

export const imageName = repo2.repositoryUrl;

const registryInfo = repo2.registryId.apply(async id => {
    const credentials = await aws.ecr.getCredentials({ registryId: id });
    const decodedCredentials = Buffer.from(credentials.authorizationToken, "base64").toString();
    const [username, password] = decodedCredentials.split(":");
    if (!password || !username) {
        throw new Error("Invalid credentials");
    }
    return {
        server: credentials.proxyEndpoint,
        username: username,
        password: password,
    };
});

// Build and publish the container image.
const image = new docker.Image("my-image", {
    build: {
      context : "/Users/.../ExampleProject",
      dockerfile: "/Users/.../ExampleProject/abc/Dockerfile", 
    },
    registry: registryInfo,
    imageName : pulumi.interpolate`${imageName}:v0.0.1`, 
});
My Pulumi codebase is separate from my application (
ExamplProject
)codebase..
l
Is app.jar being put at / in the image? If not, that'll be a problem. Your entrypoint is
java -jar /app.jar
.
i
@able-train-72108 let me know if that answers your question. Sorry I am new to Pulumi and bazel.
l
To paraphrase: does openjdk:8-jdk-alpine set WORKDIR?
i
If I comment out the
COPY ${JAR_FILE} app.jar
, it works
l
Really? If you don't copy the jar into the image, the image works? Weird.
i
I meant I am able to build the image and push it to AWS ECR. The image would be empty, I believe
l
Okay. That implies that
${JAR_FILE}
doesn't exist. Can you confirm that it does or does not?
a
@incalculable-thailand-44404 yes it answers my question. You said "it creates a new directory called
/ExampleProject/bazel-bin/abc
" then you should change ARG JAR_FILE=./abc/abc_bin.jar to ARG JAR_FILE=./bazel-bin/abc/abc_bin.jar
since the context of the docker build is ExampleProject, the COPY path should be based on this folder
i
Copy code
> [2/2] COPY ./bazel-bin/abc/abc_bin.jar app.jar:
    ------
    failed to compute cache key: "/bazel-bin/abc/abc_bin.jar" not found: not found
a
strange, it looks like the file is not there in the ExampleProject directory
🎉 1
i
weird, it works OK if I run Docker client build command like this from commandline inside
ExampleProject
:
Copy code
docker build -t <http://12334.dkr.ecr.us-west-2.amazonaws.com/abc-staging-520a243:0.0.3|12334.dkr.ecr.us-west-2.amazonaws.com/abc-staging-520a243:0.0.3> -f abc/Dockerfile ./bazel-bin
a
oh, but your context with docker cli is ./bazel-bin and not ./ExampleProject like you have in pulumi code
can you try to change the context to /Users/.../ExampleProject/bazel-bin ?
i
sure
ah nice... that does not error out. @able-train-72108 and @little-cartoon-10569 thanks a lot...really appreciate the help!
a
no problem, glad I could help 🙂
i
Is there good reading you recommend for Docker commands/tutorial?
a
the dockerfile reference is pretty good: https://docs.docker.com/engine/reference/builder/
🙏 1
for tutorial, I don't know. I've been using docker since 2016, I don't remember where I first learned it 😅
🙌 1
i
I was actually reading the Pulumi comments for the dockerbuild fields :
Copy code
export interface DockerBuild {
    /**
     * context is a path to a directory to use for the Docker build context, usually the directory
     * in which the Dockerfile resides (although dockerfile may be used to choose a custom location
     * independent of this choice). If not specified, the context defaults to the current working
     * directory; if a relative path is used, it is relative to the current working directory that
     * Pulumi is evaluating.
     */
    context?: pulumi.Input<string>;....
}
This and my lack of expertise on Docker is what made me point the context to
ExampleProject/abc
Copy code
usually the directory
     * in which the Dockerfile resides
👍 1
any idea how we can specify
--platform linux/amd64
while creating a docker build inside Pulumi ?
a
the DockerBuild class as a ExtraOptions member, you should pass it there
Copy code
//
        // Summary:
        //     An optional catch-all list of arguments to provide extra CLI options to the docker
        //     build command. For example `{'--network', 'host'}`.
        [Input("extraOptions", false, false)]
        public InputList<string>? ExtraOptions