Skip to content

Add RPM and deb packaging for cortex binary #2838

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

Merged
merged 3 commits into from
Aug 5, 2020

Conversation

jdbaldry
Copy link
Contributor

@jdbaldry jdbaldry commented Jul 6, 2020

What this PR does:
Adds tooling that can be used to build RPM and deb packages for cortex configured using the single-process-config.yaml. Continuing the practice in the Makefile, building the packages only requires access to a Docker runtime.

It also includes makeshift integration tests that confirm that the packages can be installed on CentOS or Debian and that the cortex service can be started. Dockerfiles for these images are also included.

This PR achieves the goal of providing a mechanism for building packages for cortex but needs CI integration. I want to see if this is the direction we would like to head in.

Checklist

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

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

lgtm, feel free to ping me when you get the DCO sorted out and I'll approve it. The test failure looks like unrelated flake.

@jdbaldry
Copy link
Contributor Author

jdbaldry commented Jul 7, 2020

Thanks @jtlisi, I've sorted out the DCO now.
A few questions:

  • do we want docs and changelog updates for this change?
  • should I configure the builds in CI before merging?
  • is it okay to push the utility images (fpm, debian-systemd, centos-systemd) to quay or should they be somewhere else?

@jdbaldry
Copy link
Contributor Author

jdbaldry commented Jul 8, 2020

@pracucci I have fixed up the packages target prerequisites so now just running make test-packages should build all the binaries, then the packages, and finally run the limited smoke test.

The packages end up in the dist directory after a make packages, let me know if there is anything extra I need to do for these to be included in the release artifacts.

@pracucci
Copy link
Contributor

pracucci commented Jul 9, 2020

I've just run make packages and fails with this error:

...
[Warning] One or more build-args [goproxyValue] were not consumed
Successfully built 979bed1f3e58
Successfully tagged quay.io/cortexproject/fpm:latest
docker tag quay.io/cortexproject/fpm quay.io/cortexproject/fpm:packaging-189dd535d
touch packaging/fpm/.uptodate
>>>> Entering build container: packages
make: Entering directory '/src/github.com/cortexproject/cortex'
rm -fr ./dist
mkdir -p ./dist
GOOS="linux"  GOARCH="amd64" CGO_ENABLED=0 go build -ldflags "-X main.Branch=packaging -X main.Revision=189dd535d -X main.Version=1.2.0 -extldflags \"-static\" -s -w" -tags netgo -o ./dist/cortex-linux-amd64   ./cmd/cortex
/bin/sh: go: not found
make: *** [Makefile:229: dist/cortex-linux-amd64] Error 127
make: Leaving directory '/src/github.com/cortexproject/cortex'

Could you take a look, please?

@gouthamve
Copy link
Contributor

I think this is the right approach tbh!

Interesting make packages worked for me (on Linux). make test-packages failed though.

Step 6/8 : RUN rm -f /lib/systemd/system/multi-user.target.wants/* 	/etc/systemd/system/*.wants/* 	/lib/systemd/system/local-fs.target.wants/* 	/lib/systemd/system/sockets.target.wants/*udev* 	/lib/systemd/system/sockets.target.wants/*initctl* 	/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup* 	/lib/systemd/system/systemd-update-utmp*
 ---> Running in 7c5ffd0eadd1
Removing intermediate container 7c5ffd0eadd1
 ---> e0aacd741e0f
Step 7/8 : VOLUME [ "/sys/fs/cgroup" ]
 ---> Running in b597ed89fbae
Removing intermediate container b597ed89fbae
 ---> 31f01f27f21f
Step 8/8 : CMD ["/lib/systemd/systemd"]
 ---> Running in 8a3f43e35ad3
Removing intermediate container 8a3f43e35ad3
 ---> 56496b3c6585
[Warning] One or more build-args [goproxyValue revision] were not consumed
Successfully built 56496b3c6585
Successfully tagged quay.io/cortexproject/debian-systemd:latest
docker tag quay.io/cortexproject/debian-systemd quay.io/cortexproject/debian-systemd:packaging-799cf6bc3
touch packaging/deb/debian-systemd/.uptodate
./tools/packaging/test-packages quay.io/cortexproject/ 1.2.0
Selecting previously unselected package cortex.
(Reading database ... 7618 files and directories currently installed.)
Preparing to unpack /opt/cortex/cortex-1.2.0.deb ...
Unpacking cortex (1.2.0) ...
Setting up cortex (1.2.0) ...
Created symlink /etc/systemd/system/multi-user.target.wants/cortex.service -> /etc/systemd/system/cortex.service.
Cortex not ready in 5 attempts
Testing image: quay.io/cortexproject/debian-systemd with command: 'dpkg -i /opt/cortex/cortex-1.2.0.deb' failed
make: *** [Makefile:283: test-packages] Error 1

@jdbaldry
Copy link
Contributor Author

jdbaldry commented Jul 10, 2020

@pracucci I'm unable to reproduce your issue with either make clean && make packages or make clean && make packages PACKAGE_IN_CONTAINER=false, the latter of course depends on the availability of the fpm command. The error you posted looks similar to what you mentioned the other day and should be fixed now that I have added dist/cortex-linux-amd64 as a prequisite for the PHONY packages target which ensures that the dist/cortex-linux-amd64 target is built outside of the packaging container before we proceed with packaging.

@gouthamve I don't know much about how you are supposed to test RPM/deb packages so I'm not super pleased with the smoke tests as they are. I'm happy to implement any alternatives if you have ideas. In the mean time, I've upped the retry timeout for the test-packages script and added a variable that will leave the containers around for debugging. All it does is make a curl request to the cortex ready endpoint and expects a ready response, retrying every second for ~ten seconds. Unfortunately, I'm also struggling to reproduce this locally, it just works on my machine haha.

Thanks to you both for being so patient with this PR!

Signed-off-by: Marco Pracucci <[email protected]>
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.

Thanks @jdbaldry. I tried with the latest version and both make packages and make test-packages worked. I've pushed a commit to update RELEASE process, mentioning we should build packages and attach them to the release on GitHub (which looks an easy win). Approved!

@pracucci pracucci merged commit 97691c0 into cortexproject:master Aug 5, 2020
@pracucci pracucci deleted the packaging branch August 5, 2020 08:13
@pracucci pracucci mentioned this pull request Aug 5, 2020
3 tasks
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.

4 participants