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

Switch to GHA and GHCR for image building and hosting #31

Merged
merged 41 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8d39a3d
Switch to GHA
urschrei Apr 2, 2024
cfcf684
Match makefile to renamed Dockerfiles for now
urschrei Apr 3, 2024
b5b041a
Try to push base image before building contingent images
urschrei Apr 3, 2024
de5d51d
Typo fix
urschrei Apr 3, 2024
f71188f
Jobs are now dependent
urschrei Apr 3, 2024
fa3251e
???
urschrei Apr 3, 2024
6eb401d
Fix base image name
urschrei Apr 3, 2024
7e144ca
Try to fix env base image name
urschrei Apr 3, 2024
189a678
More env fix
urschrei Apr 3, 2024
f768980
Try setting GHCR tag explicitly
urschrei Apr 3, 2024
55374a8
Modify dependent image tag names with ghcr
urschrei Apr 3, 2024
e8f9984
Simplify
urschrei Apr 3, 2024
0a44736
Tag dependent images with ghcr so they're uploaded there
urschrei Apr 3, 2024
93d23a2
Remove Makefile setup
urschrei Apr 3, 2024
bd390b0
Update Dockerfile URL comments
urschrei Apr 3, 2024
0813b2a
Add linux/arm64 platform
urschrei Apr 3, 2024
199712e
Define separate test and push steps
urschrei Apr 3, 2024
5e8d668
No multi-platform for now
urschrei Apr 3, 2024
4632b31
Don't mention multi-platform in output
urschrei Apr 3, 2024
661c8de
Try to fix multi-platform push
urschrei Apr 3, 2024
542dc1a
Fix platforms typo
urschrei Apr 3, 2024
29eb3c9
Disable multi-platform again
urschrei Apr 3, 2024
daf0e41
Ensure git is available in our containers
urschrei Apr 3, 2024
4525b7f
Try to detect container and run a test for geo
urschrei Apr 3, 2024
133c2da
Fix test command setup
urschrei Apr 3, 2024
df5bf1c
Ensure cmake is available in geo-ci
urschrei Apr 3, 2024
04c1459
More specific tests
urschrei Apr 3, 2024
d6b5f8e
Try not using slim
urschrei Apr 3, 2024
63efd15
Fix test typos
urschrei Apr 3, 2024
36da62e
Ensure sqlite3 is present
urschrei Apr 3, 2024
c8bd434
README update
urschrei Apr 3, 2024
e60a8ca
README typo fix
urschrei Apr 3, 2024
5719f4b
Use same sqlite lib in all images
urschrei Apr 3, 2024
df0ff8e
Use map of image name / test commands for sub-images
urschrei Apr 4, 2024
75a9d69
Try to remove QEMU
urschrei Apr 4, 2024
b47710c
Remove SQlite3 deps
urschrei Apr 4, 2024
1378cff
Add proj-sys tests
urschrei Apr 4, 2024
cfe241c
Test proj-sys
urschrei Apr 4, 2024
cda435b
Fix typo
urschrei Apr 4, 2024
830de1c
Build rustc MSRV + two most recent versions
urschrei Apr 4, 2024
f97d761
Don't trim trailing 0 in Rust 1.70
urschrei Apr 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions .github/workflows/imagebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Build and Push Georust Docker Images

on:
push:
tags-ignore:
- '**'
branches:
- main
- staging
- trying
pull_request:
merge_group:

env:
LIBPROJ_VERSION: 9.4.0
MAIN_IMAGE_NAME: libproj-builder

jobs:
build_main_image:
name: Build the main image for geo and proj
runs-on: ubuntu-latest

strategy:
matrix:
rust_version: ["1.70", 1.76, 1.77]

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
urschrei marked this conversation as resolved.
Show resolved Hide resolved

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set Up Builder
run: |
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap

- name: Build and export main image to Docker
uses: docker/build-push-action@v5
with:
file: ./dockerfiles/${{ env.MAIN_IMAGE_NAME }}
push: false
load: true
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/${{ env.MAIN_IMAGE_NAME }}:proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}
build-args: |
RUST_VERSION=${{ matrix.rust_version }}
PROJ_VERSION=${{ env.LIBPROJ_VERSION }}

- name: Push main image
uses: docker/build-push-action@v5
with:
file: ./dockerfiles/${{ env.MAIN_IMAGE_NAME }}
push: true
load: false
# platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ github.repository_owner }}/${{ env.MAIN_IMAGE_NAME }}:proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}
outputs: type=docker,dest=/tmp/${{ env.MAIN_IMAGE_NAME }}-proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}.tar
build-args: |
RUST_VERSION=${{ matrix.rust_version }}
PROJ_VERSION=${{ env.LIBPROJ_VERSION }}

build_dependent_images:
name: Build dependent images for geo and proj
needs: build_main_image
runs-on: ubuntu-latest

strategy:
matrix:
subimages: [
{image: geo-ci, testcmd: "git clone https://github.com/georust/geo && cd geo && cargo test --no-default-features && cargo test && cargo test --all-features"},
{image: proj-ci, testcmd: "git clone https://github.com/georust/proj && cd proj && cargo test --no-default-features && cargo test --features bundled_proj && cargo test --features network && cd proj-sys && _PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC=0 cargo test && _PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC=1 cargo test --features bundled_proj"},
{image: proj-ci-without-system-proj, testcmd: "git clone https://github.com/georust/proj && cd proj && cargo test --features bundled_proj && cd proj-sys && _PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC=1 cargo test"}
]
rust_version: ["1.70", 1.76, 1.77]

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set Up Builder
run: |
docker buildx create --name mybuilder
docker buildx use mybuilder
docker buildx inspect --bootstrap

- name: Build ${{ matrix.subimages.image }}
uses: docker/build-push-action@v5
with:
file: ./dockerfiles/${{ matrix.subimages.image }}
push: false
load: true
platforms: linux/amd64
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.subimages.image }}:proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}
build-args: |
RUST_VERSION=${{ matrix.rust_version }}
PROJ_VERSION=${{ env.LIBPROJ_VERSION }}

- name: Test ${{ matrix.subimages.image }}
run: |
docker run --rm ghcr.io/${{ github.repository_owner }}/${{ matrix.subimages.image }}:proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }} /bin/bash -c "${{ matrix.subimages.testcmd }}"

- name: Push tested ${{ matrix.subimages.image }} image
uses: docker/build-push-action@v5
with:
file: ./dockerfiles/${{ matrix.subimages.image }}
push: true
load: false
# platforms: linux/amd64,linux/arm64
tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.subimages.image }}:proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}
outputs: type=docker,dest=/tmp/${{ matrix.subimages.image }}-proj-${{ env.LIBPROJ_VERSION }}-rust-${{ matrix.rust_version }}.tar
build-args: |
RUST_VERSION=${{ matrix.rust_version }}
PROJ_VERSION=${{ env.LIBPROJ_VERSION }}
80 changes: 0 additions & 80 deletions Makefile

This file was deleted.

58 changes: 9 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,30 @@ number tag as well, e.g. `rust:1.45.1`. Similarly we could publish a new tag
for each minor patch (`geo-ci:rust-1.50.0`, `geo-ci:rust-1.50.1`, etc.), but
running CI against each patch seems like overkill at this point.

## How to Update Rust
**New images are built by Github Actions and published to the Github Container Registry if tests pass**
Copy link
Member

@michaelkirk michaelkirk Apr 4, 2024

Choose a reason for hiding this comment

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

The containers are published regardless of if the PR is merged, right? Ideally it'd be nice to not publish until merged into main but it seems non-trivial - building the three downstream containers across different jobs is nice for parallelism, but it means we can't rely on the local registry.

I can live with things as you have them now - but if you can think of an easy way to hold off on publishing until a merge into main, that'd be cool. Otherwise we can leave it for future work.

Copy link
Member Author

Choose a reason for hiding this comment

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

GHA now has the ability to trigger a job if a PR is merged.
In order to take advantage of that, we'd have to add a few new moving parts:

  1. Upload built libproj-builder x rust versions (for now) images as artifacts
  2. Upload each sub-image x rust version artifact
  3. On successful merge, download all the above again, then push to the registry.

It can be done, but it'll be easier if we can implement your no-Rust-for-main-image idea first. It will also mean duplicating the rust version and image name matrices because matrices can't be shared between jobs. That strikes me as error-prone, so we might have to explore building matrices from JSON files at job run time.

Copy link
Member

Choose a reason for hiding this comment

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

My first though was to keep the publish step in the existing workflow, but gate it on a if branch == main check.

I'm happy to follow up with that later though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that might be a lot easier…


### Prerequisites
## How to Update the Rust Version

It's assumed that you have a directory structure containing dependent georust repositories like this:

$ ls
docker-containers # this repository
geo # needed to run tests
proj # needed to run tests
### Add a new Rust version

### add a new Rust version
edit the `.github/workflows/imagebuild.yml` file

echo "1.69" >> rust-versions.txt
Add the Rust version you wish to add to the **two** `rust_version` matrices:

# build containers
./run-rust.sh 1.69 -- make build-all
#### Example

# run some tests on the new containers
urschrei marked this conversation as resolved.
Show resolved Hide resolved
./run-rust.sh 1.69 -- make test-all

# If everythig looks good, you can publish the new tags
./run-rust.sh 1.69 -- make publish-all

# delete any old unsupported rust versions from the file
edit rust-versions.txt

### To update multiple Rust versions in parallel

If you have multiple versions of rust you want to build/test/publish:

./run-rust.sh 1.49 1.50 -- make build-all

For more:
./run-rust.sh --help
Before: rust_version: [1.74, 1.75, 1.76]
After: rust_version: [1.74, 1.75, 1.76, 1.77]

## How to Update Proj

libproj (the cpp lib) is built using the [docker container builder
pattern](https://docs.docker.com/develop/develop-images/multistage-build/), and
then reused by multiple CI containers.

edit proj-version.txt

# All containers will need to be rebuilt when updating proj
./run-rust.sh --all -- make build-all
edit the `LIBPROJ_VERSION` variable in `imagebuild.yml`

# NOTE: I often see intermittent failures when running all the tests at once, but
# haven't found time to dig into why this is happening.
# I typically re-run failed tests by themselves to see if the failures recurs.
./run-rust.sh --all -- make test-all

./run-rust.sh --all -- make publish-all

### Update the `proj` crate

Expand All @@ -94,14 +65,3 @@ then reused by multiple CI containers.

- When the PR has merged and the `proj` crate has been published, you can update [geo](https://github.com/georust/geo) to use the new `proj` crate:

### Publishing docker containers

To publish all the containers for a version of rust:

# e.g. to publish geo-ci:rust-1.58, proj-ci:rust-1.58, etc.
./run-rust.sh 1.58 -- make publish-all

You can quickly publish multiple versions like this:

./run-rust.sh 1.58 1.59 -- make publish-all

5 changes: 3 additions & 2 deletions dockerfiles/geo-ci.Dockerfile → dockerfiles/geo-ci
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://hub.docker.com/orgs/georust/geo-ci
# https://github.com/orgs/georust/packages/container/package/geo-ci

# ------------------------------------------------------------------------------
# Final stage
Expand All @@ -7,7 +7,7 @@
ARG RUST_VERSION
ARG PROJ_VERSION

FROM georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION} as libproj-builder
FROM ghcr.io/georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION} as libproj-builder
FROM rust:$RUST_VERSION-bullseye

ARG RUST_VERSION
Expand All @@ -21,6 +21,7 @@ RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
ca-certificates \
clang \
cmake \
Copy link
Member

Choose a reason for hiding this comment

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

Why this new dependency?

git \
libtiff-dev \
pkg-config \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://hub.docker.com/orgs/georust/libproj-builder
# https://github.com/orgs/georust/packages/container/package/libproj-builder

# Builds libproj from source

Expand All @@ -14,6 +14,7 @@ RUN test -n "$PROJ_VERSION" || (echo "PROJ_VERSION ARG not set" && false)
RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y \
clang \
git \
Copy link
Member

Choose a reason for hiding this comment

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

Why this new dependency?

libcurl4-gnutls-dev \
libsqlite3-dev \
libtiff-dev \
Expand Down
5 changes: 3 additions & 2 deletions dockerfiles/proj-ci.Dockerfile → dockerfiles/proj-ci
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# https://hub.docker.com/orgs/georust/proj-ci
# https://github.com/orgs/georust/packages/container/package/proj-ci

ARG RUST_VERSION
ARG PROJ_VERSION
FROM georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION}
FROM ghcr.io/georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION}

ARG RUST_VERSION
ARG PROJ_VERSION
Expand All @@ -12,6 +12,7 @@ RUN test -n "$PROJ_VERSION" || (echo "PROJ_VERSION ARG not set" && false)
RUN apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
clang \
cmake \
Copy link
Member

Choose a reason for hiding this comment

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

Why this new dependency?

&& rm -rf /var/lib/apt/lists/*

RUN cp -r /build/usr/* /usr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# https://hub.docker.com/orgs/georust/proj-ci-without-system-proj
# https://github.com/orgs/georust/packages/container/package/proj-ci-without-system-proj

# This container is based on the libproj-builder container, which has built
# libproj, and thus has all the dependencies for building proj from source, but
Expand All @@ -7,7 +7,7 @@
ARG RUST_VERSION
ARG PROJ_VERSION

FROM georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION}
FROM ghcr.io/georust/libproj-builder:proj-${PROJ_VERSION}-rust-${RUST_VERSION}

ARG RUST_VERSION
ARG PROJ_VERSION
Expand Down
1 change: 0 additions & 1 deletion proj-version.txt

This file was deleted.

Loading