https://pulumi.com logo
#general
Title
# general
i

incalculable-thailand-44404

04/13/2022, 12:24 AM
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

able-train-72108

04/13/2022, 12:27 AM
what is the context of your DockerBuild in pulumi code?
i

incalculable-thailand-44404

04/13/2022, 12:28 AM
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

little-cartoon-10569

04/13/2022, 12:32 AM
Is app.jar being put at / in the image? If not, that'll be a problem. Your entrypoint is
java -jar /app.jar
.
i

incalculable-thailand-44404

04/13/2022, 12:32 AM
@able-train-72108 let me know if that answers your question. Sorry I am new to Pulumi and bazel.
l

little-cartoon-10569

04/13/2022, 12:32 AM
To paraphrase: does openjdk:8-jdk-alpine set WORKDIR?
i

incalculable-thailand-44404

04/13/2022, 12:33 AM
If I comment out the
COPY ${JAR_FILE} app.jar
, it works
l

little-cartoon-10569

04/13/2022, 12:34 AM
Really? If you don't copy the jar into the image, the image works? Weird.
i

incalculable-thailand-44404

04/13/2022, 12:34 AM
I meant I am able to build the image and push it to AWS ECR. The image would be empty, I believe
l

little-cartoon-10569

04/13/2022, 12:35 AM
Okay. That implies that
${JAR_FILE}
doesn't exist. Can you confirm that it does or does not?
a

able-train-72108

04/13/2022, 12:35 AM
@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

incalculable-thailand-44404

04/13/2022, 12:37 AM
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

able-train-72108

04/13/2022, 12:41 AM
strange, it looks like the file is not there in the ExampleProject directory
🎉 1
i

incalculable-thailand-44404

04/13/2022, 12:46 AM
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

able-train-72108

04/13/2022, 12:48 AM
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

incalculable-thailand-44404

04/13/2022, 12:53 AM
sure
ah nice... that does not error out. @able-train-72108 and @little-cartoon-10569 thanks a lot...really appreciate the help!
a

able-train-72108

04/13/2022, 12:57 AM
no problem, glad I could help 🙂
i

incalculable-thailand-44404

04/13/2022, 12:58 AM
Is there good reading you recommend for Docker commands/tutorial?
a

able-train-72108

04/13/2022, 12:59 AM
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

incalculable-thailand-44404

04/13/2022, 1:06 AM
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

able-train-72108

04/14/2022, 11:08 AM
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
10 Views