Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amazon-ec2-metadata-mock: init at 1.12.0 #365690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arianvp
Copy link
Member

@arianvp arianvp commented Dec 16, 2024

A tool to simulate Amazon EC2 instance metadata.

I want to use this for better EC2 image tests.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@arianvp arianvp force-pushed the amazon-ec2-metadata-mock branch from 34d6661 to e95eb9a Compare December 16, 2024 20:45
Comment on lines +22 to +26
subPackages = [ "cmd/" ];

postBuild = ''
mv "$GOPATH/bin/cmd" "$GOPATH/bin/$mainProgram"
'';
Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to enumerate each cmd/{command} in subPackages to automatically get the binary in $out/bin?

Copy link
Member Author

@arianvp arianvp Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one package named cmd. They don't have a cmd/ec2-metadata-mock folder as would be idiomatic. This is why I need this workaround.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it.

$ tree /nix/store/r2fcrxh07csw9fs1cld9px13ydvj577m-amazon-ec2-metadata-mock-1.12.0
/nix/store/r2fcrxh07csw9fs1cld9px13ydvj577m-amazon-ec2-metadata-mock-1.12.0
└── bin
    └── cmd

Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see why we have to do this. The source layout is cursed.

amazon-ec2-metadata-mock/
└── cmd/
    └── amazon-ec2-metadata-mock.go

We can only do cmd for subpackages since each folder is its own package. Since there's no ec2-metadata-mock folder, we can't do cmd/ec2-metadata-mock. Upstream would need this layout instead:

amazon-ec2-metadata-mock/
└── cmd/
    └── ec2-metadata-mock/
        └── *.go

Copy link
Contributor

@commiterate commiterate Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR to upstream (since this is breaking Go convention): aws/amazon-ec2-metadata-mock#224

Assuming that gets merged, this should be good (with the source hash fixed):

pkgs/by-name/am/amazon-ec2-metadata-mock/package.nix

{
  lib,
  buildGoModule,
  fetchFromGitHub,
  nix-update-script,
  versionCheckHook,
}:

buildGoModule rec {
  pname = "amazon-ec2-metadata-mock";
  version = "1.12.1";

  src = fetchFromGitHub {
    owner = "aws";
    repo = "amazon-ec2-metadata-mock";
    tag = "v${version}";
    hash = lib.fakeHash;
  };

  vendorHash = "sha256-jRJX4hvfRuhR5TlZe7LsXaOlUCwmQGem2QKlX3vuk8c=";

  subPackages = [ "cmd/ec2-metadata-mock" ];

  doInstallCheck = true;

  nativeInstallCheckInputs = [ versionCheckHook ];

  versionCheckProgram = "${builtins.placeholder "out"}/bin/ec2-metadata-mock";

  versionCheckProgramArg = "--version";

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = {
    description = "Tool to simulate Amazon EC2 instance metadata";
    homepage = "https://github.com/aws/amazon-ec2-metadata-mock";
    license = lib.licenses.asl20;
    mainProgram = "ec2-metadata-mock";
    maintainers = with lib.maintainers; [ arianvp ];
  };
}

Edit: Added versionCheckProgram = "${builtins.placeholder "out"}/bin/ec2-metadata-mock";.

Copy link
Contributor

@commiterate commiterate Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build output:

$ nix-build -A amazon-ec2-metadata-mock                                           
this derivation will be built:
  /nix/store/nflp1z2xmcv31bxgwwx99k0qrk5jilv6-amazon-ec2-metadata-mock-1.12.0.drv
building '/nix/store/nflp1z2xmcv31bxgwwx99k0qrk5jilv6-amazon-ec2-metadata-mock-1.12.0.drv'...
Using versionCheckHook
Running phase: unpackPhase
unpacking source archive /nix/store/crycqj02168xghr6npqvjs3kg3xkikgs-source
source root is source
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Running phase: buildPhase
Building subPackage ./cmd/ec2-metadata-mock
Running phase: checkPhase
?       github.com/aws/amazon-ec2-metadata-mock/cmd/ec2-metadata-mock   [no test files]
Running phase: installPhase
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0
shrinking /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin/ec2-metadata-mock
checking for references to /build/ in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0...
patching script interpreter paths in /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0
stripping (with command strip and flags -S -p) in  /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin
Running phase: installCheckPhase
Executing versionCheckPhase
Successfully managed to find version 1.12.0 in the output of the command /nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0/bin/ec2-metadata-mock --version
2024/12/17 18:25:56 Warning: Failed to find home directory due to error: exec: "getent": executable file not found in $PATH
v1.12.0
Finished versionCheckPhase
no Makefile or custom installCheckPhase, doing nothing
/nix/store/wqmlv0g809zrkb3q4r9ap12lcppkwadf-amazon-ec2-metadata-mock-1.12.0

Looks like there's some pesky dependency on getent causing this line:

2024/12/17 18:25:56 Warning: Failed to find home directory due to error: exec: "getent": executable file not found in $PATH

https://github.com/aws/amazon-ec2-metadata-mock/blob/98afdd52d3344779e2174448db8e5a37973ab574/pkg/config/config.go#L43-L50

Seems to be for config file handling.

Copy link
Contributor

@commiterate commiterate Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getent dependency is because they're using mitchellh/go-homedir which does this:

https://github.com/mitchellh/go-homedir/blob/af06845cf3004701891bf4fdb884bfe4920b3727/homedir.go#L114

They need to migrate off that package since it's archived and they should be using the built-in os package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue upstream for removing the mitchellh/go-homedir dependency.

aws/amazon-ec2-metadata-mock#225

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like upstream is already reviewing the 2 PRs (they've approved the GitHub Actions workflow runs for them). Might be merged pretty quickly.

@arianvp
Copy link
Member Author

arianvp commented Dec 27, 2024

I'd prefer to get this merged as is as I need it :D

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Dec 29, 2024
};

meta = {
description = "A tool to simulate Amazon EC2 instance metadata";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "A tool to simulate Amazon EC2 instance metadata";
description = "Tool to simulate Amazon EC2 instance metadata";

src = fetchFromGitHub {
owner = "aws";
repo = "amazon-ec2-metadata-mock";
rev = "refs/tags/v${version}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rev = "refs/tags/v${version}";
tag = "v${version}";

The tag parameter was recently added to make this shorter.

LGTM otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 10.rebuild-darwin: 1 10.rebuild-linux: 1-10 10.rebuild-linux: 1 11.by: package-maintainer This PR was created by the maintainer of the package it changes 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants