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

Add a docker image for CI #1633

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

Conversation

daamien
Copy link
Contributor

@daamien daamien commented Apr 4, 2024

Following a discussion on the discord channel:

Here's a basic docker image with all the requirements to build a PGRX project in a CI job. This saves a lot of CI minutes, especially the cargo pgrx init step which is quite long.

By default, the image is based on the latest version available but it can be overriden with --build-arg PGRX_VERSION=0.11.3

This could be completed with a CI action to build and push the image automatically on dockerhub, like this

https://github.com/daamien/docker-pgrx/blob/latest/.github/workflows/build-push.yaml

This would require to add secrets variables in the Github account for DOCKERHUB_USERNAME and DOCKERHUB_TOKEN

This would also provide an easy way to test against alpha/beta versions by simply pulling any version like this

docker pull pgcentralfoundation/pgrx:0.12.0-alpha.1

A basic image with all the requirements to build a PGRX project
in a CI job. This saves a lot of CI minutes, especially the
`cargo pgrx init` step which is quite long.

By default, the image is based on the latest version available
but it can be overriden with `--build-arg PGRX_VERSION=0.11.3`
@workingjubilee
Copy link
Member

@daamien Could you add a workflow in that actually would use this? It's not enough to just put it in the CI folder, gotta actually make it part of the tests.

@workingjubilee
Copy link
Member

And I don't mean a workflow to put it on DockerHub or whatever, I mean something that would use it to run the test suite on top of it.

@thomcc
Copy link
Contributor

thomcc commented Apr 4, 2024

@daamien We don't run the slow cargo pgrx init in CI. We use a prebuilt PG, which means the cargo pgrx init step is very fast: image

The downside of using a prebuilt postgres is that it doesn't have debug-asserts enabled. In practice this is kind of fine but is a real deficiency in our CI flow. Unfortunately fixing this requires (as you mentioned) uploading the container to something like dockerhub or (more likely for our case, for trust reasons) GHCR. All this isn't trivial.

@workingjubilee
Copy link
Member

does it require the upload first? 😵‍💫 gah.

@daamien
Copy link
Contributor Author

daamien commented Apr 4, 2024

Thanks for the feedback !

What is the problem with uploading the image to a registry ? The image will be quite big ( roughly 1,5Go ) but the upload would happen only when a tag is pushed on the PGRX repo. So once a month, or so. That seems acceptable. Anyway I think it's also possible to let dockerhub build the image (via a webhook) and in that case there's no upload at all....

Regarding the examples of CI configuration, I work mostly on gitlab.com and I have some custom jobs that wouldn't apply for a general usage, but I guess that the job below would be a good example to start with:

pgrx:test:
  stage: test
  image: pgcentralfoundation/pgrx:0.11.3
  script:
    - cargo pgrx test $PGVER --verbose
  parallel:
    matrix:
      - PGVER: pg12
      - PGVER: pg13
      - PGVER: pg14
      - PGVER: pg15
      - PGVER: pg16

I'm less familiar with github actions, but it would look like this

name: PGRX tests
on: [push]
jobs:
  test:
    strategy:
      matrix:
        pgver: [pg12, pg13, pg14, pg15, pg16 ]
    name: PGRX tests on ${{ matrix.pgver }}
    runs-on: ubuntu-latest
    container:  pgcentralfoundation/pgrx:0.11.3
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4
      - name: Test on  ${{ matrix.pgver }}
        run: cargo pgrx test ${{ matrix.pgver }} --verbose

@theory
Copy link
Contributor

theory commented Apr 12, 2024

Unfortunately I don't think this image will work for GitHub actions due to /actions/checkout#956: You can't checkout a repo unless you run as root in the image, and you can't run Postgres as root. @eeeebbbbrrrr is working on a workaround to allow pgrx to run Postgres as a different system user. Discussion thread.

@theory
Copy link
Contributor

theory commented Apr 16, 2024

There's also this bit of documentation:

Docker actions must be run by the default Docker user (root). Do not use the USER instruction in your Dockerfile, because you won't be able to access the GITHUB_WORKSPACE directory. For more information, see "Variables" and USER reference in the Docker documentation.

Ultimately we're going to have to create a GitHub action in JavaScript I think. :-(

@theory
Copy link
Contributor

theory commented Apr 24, 2024

With the new --runas and --pgdata optoins in v0.11.3, I've updated pgxn-tools with a new command, pgrx-build-test, does the full build/test/install/installcheck dance (installcheck only if it appears to be in a Makefile. I'm now using it in the pg-jsonschema-boon CI workflow (sample run).

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.

None yet

4 participants