Has anyone else run into an issue when trying to u...
# general
e
Has anyone else run into an issue when trying to use Pulumi to build docker images, where you have a single Dockerfile, but two different targets in that Dockerfile and you want to build those two targets seperately? For example... I have a Dockerfile which has a "base" target, and then two additional targets "migrations" and "production" which extend from the "base". I have two Image resources in my Pulumi code which target the "migrations" and "production" targets separately. However, when I do this, despite the resources having different "names" I get the error:
Duplicate resource URN
on the second image build. The URN in question looks like one that is auto created by the Image resource with a name of
838fab2f-container
.
d
Can you post the code please? The duplicate URN refers to the first positional argument in the resource
e
@dry-keyboard-94795 here is the relevant code:
Copy code
export const migratorRepo = new awsx.ecr.Repository(`${stackName}-migrator`, {
  lifecyclePolicy: {
    rules: [{ maximumNumberOfImages: 25, tagStatus: 'any' }],
  },
});

export const appsRepo = new awsx.ecr.Repository(`${stackName}-api`, {
  lifecyclePolicy: {
    rules: [{ maximumNumberOfImages: 25, tagStatus: 'any' }],
  },
});

checkForBuildx();

const migratorImage = new awsx.ecr.Image(PREFIX + 'migrator', {
  repositoryUrl: migratorRepo.url,
  context: path.join(__dirname, '../../../../'),
  dockerfile: path.join(__dirname, '../../', 'Dockerfile'),
  platform: 'linux/amd64',
  target: 'migration',
  cacheFrom: ["base"],
  args: {
    BUILDKIT_INLINE_CACHE: "1",
  },
});

const apiImage = new awsx.ecr.Image(PREFIX + 'api', {
  repositoryUrl: appsRepo.url,
  context: path.join(__dirname, '../../../../'),
  dockerfile: path.join(__dirname, '../../', 'Dockerfile'),
  platform: 'linux/amd64',
  target: 'production',
  cacheFrom: ["base"],
  args: {
    BUILDKIT_INLINE_CACHE: "1",
  },
});
However, with this code I always get the following error:
Copy code
error: Duplicate resource URN 'urn:pulumi:sandbox::emabas20-be::awsx:ecr:Image$docker:index/image:Image::838fab2f-container'; try giving it a unique name
d
Yep, I see the code looks incorrect here: https://github.com/pulumi/pulumi-awsx/blob/52e698db4d85d7fd4fa292027d04766ce4b1ceba/awsx/ecr/image.ts#L93 As a workaround, you can give one of the images a stub
args
so it generates a different name
Can you report this here please: https://github.com/pulumi/pulumi-awsx/issues I don't understand why they aren't using the resourceName in the computation
e
So basically just fake it out, by adding something like a
X_IMAGE_NAME='migrator'
arg (which does nothing) to bust the cache?
d
Yep (though not cache related)
e
Right, poor choice of word