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

Migrate CircleCI workflows to GitHub Actions (1/3) #3302

Merged
merged 4 commits into from
Oct 12, 2020

Conversation

AzfaarQureshi
Copy link
Contributor

@AzfaarQureshi AzfaarQureshi commented Oct 8, 2020

What this PR does

This is PR 1/3 of migrating Cortex's CI from CircleCI to GitHub Actions:

Part 1/3 👈

  • create test-build-deploy workflow under .github/workflows
  • add README
  • adding the 3 base jobs
    • lint
    • test
    • build
  • these jobs are run async and share no dependencies with each other
  • workflow is run when a commit is pushed to master or when any PR is opened. However CD jobs will only run on the master branch and will be skipped otherwise
  • all jobs in following PRs are dependant on one or more of these jobs finishing

Part 2/3

  • adding jobs dependant on build
    • integration
    • integration-config-db
  • This PR completes the CI portion of migration. The following PR will finish the remaining CD portion of the migration

Part 3/3

  • This PR completes the migration from CircleCI to GitHub Actions
    • deploy_website is dependant on build, test
    • deploy is dependant on build, test, lint, integration, integration-config-db
  • CD jobs will only run on the master branch and will be otherwise skipped

Which issue(s) this PR fixes:

Fixes #3274

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Comment on lines +16 to +19
- name: Sym Link Expected Path to Workspace
run: |
mkdir -p /go/src/github.com/cortexproject/cortex
ln -s $GITHUB_WORKSPACE/* /go/src/github.com/cortexproject/cortex
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A significant number of commands in the Makefile were hardcoded with an assumed file structure of the CI container. make sure previous commands don’t break a symlink was created instead from the hardcoded “expected” working directory go/src/github.com/cortexproject/cortex to the actual working directory $GITHUB_WORKSPACE.

.github/workflows/test-build-deploy.yml Show resolved Hide resolved
Comment on lines +111 to +117
- name: Zip Images
run: tar -zcvf images.tar.gz /tmp/images
- name: Upload Images Artifact
uses: actions/upload-artifact@v2
with:
name: Docker Images
path: ./images.tar.gz
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of Oct 2020 GitHub Actions does not persist between different jobs in the same workflow. Each job is run on a fresh virtual environment. As such, we need to upload and download artifacts to share data between jobs.

Docker Images are zipped before uploading as a workaround. The images contain characters that are illegal in the upload-artifact action.

@shovnik shovnik force-pushed the gha-migration-1 branch 2 times, most recently from d383cf7 to 19f90c4 Compare October 8, 2020 17:33
@AzfaarQureshi AzfaarQureshi force-pushed the gha-migration-1 branch 2 times, most recently from bb100e5 to df057f0 Compare October 8, 2020 18:21
shovnik and others added 3 commits October 8, 2020 14:22
Signed-off-by: Azfaar Qureshi <azfaarq@amazon.com>
Signed-off-by: Azfaar Qureshi <azfaarq@amazon.com>
Signed-off-by: Azfaar Qureshi <azfaarq@amazon.com>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Very good job! Overall LGTM. I just left few questions here and there, but I can't see any blocker.

.github/README.md Outdated Show resolved Hide resolved
.github/workflows/test-build-deploy.yml Show resolved Hide resolved
.github/workflows/test-build-deploy.yml Outdated Show resolved Hide resolved
.github/workflows/test-build-deploy.yml Outdated Show resolved Hide resolved
lint:
runs-on: ubuntu-latest
container:
image: quay.io/cortexproject/build-image:update-golang-1.14.9-eb0c8d4d2
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we can use something similar to defaults: &defaults in the CircleCI yaml, in order to avoid the repetition of image: quay.io/cortexproject/build-image:update-golang-1.14.9-eb0c8d4d2 and being able to define the build image only once in this file?

Copy link
Contributor

@shovnik shovnik Oct 9, 2020

Choose a reason for hiding this comment

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

There exists a "defaults" field for GitHub actions, but it automatically applies to all jobs in the workflow. The integration and integration-configs-db jobs that will be added to the workflow with PR 2/3 of the migration do not use the default container so using a default would require explicitly removing the default container from those jobs by setting them to None.

We would like to reuse setup commands and default containers with something like commands in CircleCI, but this feature is not available yet on GitHub Actions.

Status: https://github.community/t/reusing-sharing-inheriting-steps-between-jobs-declarations/16851

Copy link
Contributor Author

@AzfaarQureshi AzfaarQureshi Oct 9, 2020

Choose a reason for hiding this comment

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

GHA doesn't support yaml anchors yet because of some security reasons but they are actively working on it

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use env variable instead?

Copy link
Contributor

@pracucci pracucci Oct 12, 2020

Choose a reason for hiding this comment

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

This is not a blocker for getting this PR merged. We can discuss it separately.

Comment on lines +82 to +105
- uses: actions/upload-artifact@v2
with:
name: website public
path: website/public/
- uses: actions/upload-artifact@v2
with:
name: Frontend Protobuf
path: pkg/querier/frontend/frontend.pb.go
- uses: actions/upload-artifact@v2
with:
name: Caching Index Client Protobuf
path: pkg/chunk/storage/caching_index_client.pb.go
- uses: actions/upload-artifact@v2
with:
name: Ring Protobuf
path: pkg/ring/ring.pb.go
- uses: actions/upload-artifact@v2
with:
name: Cortex Protobuf
path: pkg/ingester/client/cortex.pb.go
- uses: actions/upload-artifact@v2
with:
name: Rules Protobuf
path: pkg/ruler/rules/rules.pb.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you figured out if we actually need to upload these artifacts? I know we do it in CircleCI but I have the feeling they're unused (at least I don't remember if we still use them anywhere).

Copy link
Contributor Author

@AzfaarQureshi AzfaarQureshi Oct 9, 2020

Choose a reason for hiding this comment

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

Oh, we included it because this PR here made it seem like there was an explicit decision to save these files. Has the situation changed? But you are right, those artifacts are not used anywhere else within CI

Copy link
Contributor

Choose a reason for hiding this comment

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

Since then we have added these files into Git, so I think #1224 is not relevant anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

(In #1399)

Copy link
Contributor

Choose a reason for hiding this comment

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

I also think we don't need to store these artifacts anymore.

Signed-off-by: Azfaar Qureshi <azfaarq@amazon.com>
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Great job, thank you very much for doing this!

(Nit: In next PRs I would suggest moving the comments from README.md into YAML files, to keep it at one place.)

- name: Sym link expected path to github workspace
run: |
mkdir -p /go/src/github.com/cortexproject/cortex
ln -s $GITHUB_WORKSPACE/* /go/src/github.com/cortexproject/cortex
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks suspicious... why create many links instead of one:

mkdir -p /go/src/github.com/cortexproject/
ln -s "$GITHUB_WORKSPACE" /go/src/github.com/cortexproject/cortex

*Note:* Docker Images are zipped before uploading as a workaround. The images contain characters that are illegal in the upload-artifact action.
```yaml
- name: Compressing Images
run: tar -zcvf images.tar.gz /tmp/images
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if compression gives us anything here. We can use tar without -z flag to make it run faster (but use more disk space).

Copy link
Contributor

Choose a reason for hiding this comment

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

The compression was in fact unnecessary. We removed it in the subsequent migration PR: #3341

steps:
- name: Checkout Repo
uses: actions/checkout@v1
- name: Sym Link Expected Path to Workspace
Copy link
Contributor

Choose a reason for hiding this comment

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

This linking is explained in README, apart from doing review, who reads that? I'd include the explanations from README directly into this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Added a comment explaining this within the code itself in the subsequent PR to address this.
#3341

lint:
runs-on: ubuntu-latest
container:
image: quay.io/cortexproject/build-image:update-golang-1.14.9-eb0c8d4d2
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to use env variable instead?

mkdir -p /go/src/github.com/cortexproject/cortex
ln -s $GITHUB_WORKSPACE/* /go/src/github.com/cortexproject/cortex
- name: Lint
run: make BUILD_IN_CONTAINER=false lint
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we set BUILD_IN_CONTAINER=false as env variable for entire workflow or at least individual jobs?

Copy link
Contributor

Choose a reason for hiding this comment

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

But BUILD_IN_CONTAINER is not an environment variable. At least, doesn't work if you set it as env variable. Am I missing anything?

Comment on lines +82 to +105
- uses: actions/upload-artifact@v2
with:
name: website public
path: website/public/
- uses: actions/upload-artifact@v2
with:
name: Frontend Protobuf
path: pkg/querier/frontend/frontend.pb.go
- uses: actions/upload-artifact@v2
with:
name: Caching Index Client Protobuf
path: pkg/chunk/storage/caching_index_client.pb.go
- uses: actions/upload-artifact@v2
with:
name: Ring Protobuf
path: pkg/ring/ring.pb.go
- uses: actions/upload-artifact@v2
with:
name: Cortex Protobuf
path: pkg/ingester/client/cortex.pb.go
- uses: actions/upload-artifact@v2
with:
name: Rules Protobuf
path: pkg/ruler/rules/rules.pb.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Since then we have added these files into Git, so I think #1224 is not relevant anymore.

@pracucci pracucci mentioned this pull request Oct 12, 2020
3 tasks
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

mkdir -p /go/src/github.com/cortexproject/cortex
ln -s $GITHUB_WORKSPACE/* /go/src/github.com/cortexproject/cortex
- name: Lint
run: make BUILD_IN_CONTAINER=false lint
Copy link
Contributor

Choose a reason for hiding this comment

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

But BUILD_IN_CONTAINER is not an environment variable. At least, doesn't work if you set it as env variable. Am I missing anything?

@pracucci pracucci merged commit 491e607 into cortexproject:master Oct 12, 2020
@pracucci
Copy link
Contributor

@AzfaarQureshi We merged the PR since it's in a good shape, but we would be glad if you could address the remaining comments in a subsequent PR. Thanks!

@pstibrany
Copy link
Contributor

pstibrany commented Oct 12, 2020

But BUILD_IN_CONTAINER is not an environment variable. At least, doesn't work if you set it as env variable. Am I missing anything?

"Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value." (from GNU Make docs)

But you say that it doesn't work when set as env variable, so perhaps there is something in our Makefile that prevents that?

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

Successfully merging this pull request may close these issues.

Proposal: Migrate Cortex CI/CD from CircleCI to GitHub Actions
4 participants