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

GHA: Build and Publish to Public ECR and Build Nix #49

Merged
merged 16 commits into from
Oct 17, 2023

Conversation

adamtajti
Copy link
Contributor

@adamtajti adamtajti commented Aug 23, 2023

We're moving our Docker image hosting from Docker Hub to AWS Public ECR Repositories.

Additionally this PR also attempts to fix failures in the tests that were undetected in the last merge as we just added these workflows.

@adamtajti adamtajti self-assigned this Aug 23, 2023
@adamtajti adamtajti changed the title Draft: Build and Publish to ECR Build and Publish to ECR Aug 24, 2023
@adamtajti adamtajti marked this pull request as ready for review August 29, 2023 20:26
@jgdef-tulip
Copy link
Contributor

Although the ECR repository may have public-ecr in its path, it's still a private registry:
Screenshot 2023-08-31 at 4 31 55 PM

@adamtajti , is the intention for the public to be able to pull these images? In which case, I think we should look into AWS public gallery? cc @aranair

@aranair
Copy link
Member

aranair commented Aug 31, 2023

Although the ECR repository may have public-ecr in its path, it's still a private registry: Screenshot 2023-08-31 at 4 31 55 PM

@adamtajti , is the intention for the public to be able to pull these images? In which case, I think we should look into AWS public gallery? cc @aranair

https://gallery.ecr.aws/u4f7y3k8/oplogtoredis I think this is the relevant public gallery entry? 🤔

@adamtajti
Copy link
Contributor Author

adamtajti commented Aug 31, 2023

I created that public repository as I initially wanted to place the images there, but there were a couple of permission issues that I faced while deploying from the garden and from my own machine as well, so I decided to stick with the private repository until we think that is important enough. Updated the README. I think it's alright that the workflow does something private for us at the moment, cause the forks won't be whitelisted by our IAM OIDC identity provider (@aranair @jgdef-tulip )

export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint --version
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be anchored with a hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

But don't we use anchors for all non-GitHub actions as a security issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, you are right, although I think that later versions of the action should provide fixes to both discovered security issues as well improve the performance of the existing functionalities. I'm ok with adding one though since it's no biggie, I'll hop back to this branch in a few hours.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like I forgot about this. Pinned down the versions.

nativeBuildInputs = [installShellFiles];
doCheck = false;
doInstallCheck = false;
nativeBuildInputs = [ installShellFiles ];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a nix linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of.

Copy link

Choose a reason for hiding this comment

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

log.Printf("Warning: mongo insert failed: %s", err)
log.Printf("Warning: mongo insert failed for doc %s: %s", id, err)
if insertResult != nil && insertResult.InsertedID != nil {
log.Printf("Warning: although the previous insert faced this error, the InsertedID wasn't nil, so we'll conclude it was a success (InterruptedDueToReplStateChange). InsertedID: %s", insertResult.InsertedID)
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 is there a way to check the type of err (e.g., for InterruptedDueToReplStateChange)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess, this worked though, so lets go with this one. There could be many different errors, this was just what I picked up. The result is apparently simply not reliable in case of insert when using replicated mongo.

@adamtajti adamtajti force-pushed the adam.workflow-built-ecr-images branch from 61f21c8 to ed84c5f Compare September 25, 2023 15:17
@adamtajti adamtajti changed the title Build and Publish to ECR Build and Publish to Public ECR Sep 25, 2023
@adamtajti adamtajti marked this pull request as draft September 25, 2023 15:19
@adamtajti adamtajti marked this pull request as ready for review September 27, 2023 13:07
@adamtajti
Copy link
Contributor Author

Ready for review again. Rebased, repushed, we are using 1:1 IAM roles for these repositories to push the images from their respective workflows.

@adamtajti adamtajti requested a review from kocsisa September 27, 2023 13:07
@adamtajti adamtajti requested a review from blikstiender October 6, 2023 05:54
@adamtajti
Copy link
Contributor Author

(fyi The tulip/tulip parts got merged)

@adamtajti adamtajti changed the title Build and Publish to Public ECR Build and Publish to Public ECR and Build Nix Oct 10, 2023
@adamtajti adamtajti changed the title Build and Publish to Public ECR and Build Nix GHA: Build and Publish to Public ECR and Build Nix Oct 10, 2023
@adamtajti adamtajti requested a review from mgaborl October 11, 2023 06:45
@adamtajti
Copy link
Contributor Author

I've included a Nix build in this pull request, which ensures that the vendorHash stays up-to-date, especially for developers who may not be as familiar with Nix, just like myself. This should also help the developer get reminded that the semantic version number should be incremented with the change as well. I've added documentation for these changes in the README file. Thanks

cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

permissions:
id-token: write # for the creds itself
Copy link
Contributor

Choose a reason for hiding this comment

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

Remind me again, the meaning behind the comment for the creds itself ?

Copy link
Contributor Author

@adamtajti adamtajti Oct 11, 2023

Choose a reason for hiding this comment

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

Honestly, I had no idea whatever this was required or not and what the comment meant. It looks like it was written by Ho Man, or someone before him and it was copied around (like over here). I remember failing the login without setting these permissions there, so I guess I assumed that it's needed over here as well, but it looks like it's not. Never looked into it deep enough. Removed the comment and removed the write perms.

Copy link
Member

Choose a reason for hiding this comment

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

id-token is required for oidc role assumption

id: generate-tag
run: |
# Extract the current version from `default.nix`. This must pass.
version=$(nix flake show . --quiet --all-systems --json | jq -r '.defaultPackage."aarch64-darwin".name' | cut -d'-' -f2-)
Copy link
Contributor

Choose a reason for hiding this comment

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

it's fine to hard-code aarch64-darwin ?

Copy link
Contributor Author

@adamtajti adamtajti Oct 11, 2023

Choose a reason for hiding this comment

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

I think it is, cause all the ${system} dicts will have the same .name attribute. Although I agree that it's ugly.

uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # 4.0.0
with:
tags: ${{ steps.setup-ecr-buildx.outputs.ecr_registry }}/tulip/oplogtoredis:${{ steps.generate-tag.outputs.TAG }}
provenance: false
Copy link
Contributor

Choose a reason for hiding this comment

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

It's outside of this PR but eventually I like the idea of attaching metadata to instances via the provenance/SLSA attestations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's just a switch to true flag, then lets change it. I'm not familiar with this feature, but it looks like that's all that we would need to do at a first glance, it writes the metadata into the image index.

@@ -3,19 +3,31 @@ name: Pull Request
on: [ pull_request ]

jobs:
nix_build:
runs-on: ubuntu-20.04
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why there's an explicit ubuntu version here for PRs, but the build & push workflow uses ubuntu-latest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, none, I just followed the pattern in this file. I just changed it to latest. For the other steps here we can't make a bump yet though, it'll need some additional dependencies to be installed. I want to do that in another round.

README.md Outdated
# TODO: default.nix: Change the `vendorHash` property to an empty string and run `nix build`.
nix build
# ...
# error: hash mismatch in fixed-output derivation '/nix/store/by8bc99ywfw6j1i6zjxcwdmc5b3mmgzv-oplogtoredis-3.0.0-go-modules.drv':
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 Author

Choose a reason for hiding this comment

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

Yeah, try reading the updated instructions, this was highly cryptic. I hope that the new one is more understandable ^^

README.md Outdated
You can build oplogtoredis from source with `go build .`, which produces a
statically-linked binary you can run. Alternatively, you can use [the public
docker image](https://hub.docker.com/r/tulip/oplogtoredis/tags/)
You can build oplogtoredis from source with `go build .`, which produces a statically-linked binary you can run. Alternatively, you can use [the public docker image](https://gallery.ecr.aws/u4f7y3k8/oplogtoredis). Previously we used to host these images in [Docker Hub](https://hub.docker.com/r/tulip/oplogtoredis/tags/). These won't be maintained anymore.
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we're approved, can't we use https://gallery.ecr.aws/tulip ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done.

@adamtajti adamtajti requested a review from jgdef-tulip October 11, 2023 17:27
@adamtajti
Copy link
Contributor Author

bump; this should get in before the redis-sentinel support.

@adamtajti adamtajti merged commit 8ad2cc1 into master Oct 17, 2023
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the adam.workflow-built-ecr-images branch October 17, 2023 12:19
@adamtajti
Copy link
Contributor Author

Gabor gave this another review and I merged this after his approval. We think that we are in a better shape now, but in-case you have further suggestions feel free to comment here further or put up further pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants