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

build(docker): Build an image for sentry CI #1658

Merged
merged 41 commits into from
Feb 10, 2023
Merged

Conversation

asottile-sentry
Copy link
Member

@asottile-sentry asottile-sentry commented Dec 1, 2022

we're moving sentry's CI from depending on both gcr.io and ghcr.io to only ghcr.io

#skip-changelog

Comment on lines -1 to -2
ARG DOCKER_ARCH=amd64

Copy link
Member Author

Choose a reason for hiding this comment

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

I deleted all the ARCH stuff here to make the dockerfile easier to build -- it now depend on the --platform argument to docker build instead of specifying the architecture as an --arg

@asottile-sentry asottile-sentry changed the title ref: build a multiarch relay image for sentry CI ref: build a elay image for sentry CI Dec 1, 2022
@asottile-sentry asottile-sentry changed the title ref: build a elay image for sentry CI ref: build a relay image for sentry CI Dec 1, 2022
@asottile-sentry asottile-sentry marked this pull request as ready for review December 1, 2022 19:16
@asottile-sentry asottile-sentry requested a review from a team December 1, 2022 19:16
@asottile-sentry asottile-sentry force-pushed the asottile-relay-multiarch branch from 60c6fc9 to d14c031 Compare December 2, 2022 16:44
@jan-auer jan-auer dismissed iker-barriocanal’s stale review January 23, 2023 09:51

@olksdr or I will take a closer look and re-approve afterwards.

Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

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

This looks good.
@asottile-sentry could you, please, merge master back and resolve the conflicts, so we could give another look and finally merge it in.

@olksdr olksdr assigned olksdr and unassigned asottile-sentry Jan 30, 2023
@olksdr olksdr requested review from jan-auer and a team January 30, 2023 13:47
@@ -15,11 +15,11 @@ BUILD_IMAGE="us.gcr.io/sentryio/relay:deps"

Copy link
Member

Choose a reason for hiding this comment

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

We should change the BUILD_IMAGE:

  • Use the GHCR or DockerHub instead of GCR
  • Use caches, but also build that image as part of this script

@@ -30,6 +30,17 @@ build-linux-release: setup-git ## build linux release of the relay
objcopy --add-gnu-debuglink target/${TARGET}/release/relay{.debug,}
.PHONY: build-linux-release

collect-source-bundle: setup-git ## copy the built relay binary to current folder and collects debug bundles
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to a script. This allows us to:

  • Call this more naturally from other scripts
  • Use it in gocd deployments
  • Publish it to GH releases

- name: ghcr.io login
run: docker login --username '${{ github.actor }}' --password '${{ secrets.GITHUB_TOKEN }}' ghcr.io

- name: build-deps
Copy link
Member

Choose a reason for hiding this comment

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

Idea: These steps could be moved to a script that we can also use locally to:

  • Build / update the builder image
  • Build the binary to a local folder (should we introduce a build/ directory?)
  • Create the release docker container w/ the binary inside

In a close follow-up, we can then replace docker-build-linux.sh in the build_binary workflow with our new script.

@jan-auer jan-auer force-pushed the asottile-relay-multiarch branch from 69c8220 to b58f526 Compare February 8, 2023 11:07
@jan-auer
Copy link
Member

jan-auer commented Feb 8, 2023

After merging, we need to

  1. Disable the GCB repository trigger
  2. Update required status checks in this repo
  3. Update freight checks by removing cloudbuild and adding required jobs:
"checks": [
  {
    "type": "github-apps",
    "config": {
      "repo": "getsentry/relay",
      "contexts": [
        "Integration Tests",
        "Test (macos-latest)",
        "Test (windows-latest)",
        "Test All Features (ubuntu-latest)",
        "Push GCR Docker Image"
      ]
    }
  }
]

Comment on lines 8 to 16
# Set the correct build target and update the arch if required.
if [[ "$ARCH" = "amd64" ]]; then
BUILD_TARGET="x86_64-unknown-linux-gnu"
elif [[ "$ARCH" = "arm64" ]]; then
BUILD_TARGET="aarch64-unknown-linux-gnu"
elif [[ "$ARCH" = "aarch64" ]]; then
BUILD_TARGET="aarch64-unknown-linux-gnu"
ARCH="arm64"
fi
Copy link
Member

Choose a reason for hiding this comment

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

Let's add an else branch that errors if no supported architecture is set, for instance:

Suggested change
# Set the correct build target and update the arch if required.
if [[ "$ARCH" = "amd64" ]]; then
BUILD_TARGET="x86_64-unknown-linux-gnu"
elif [[ "$ARCH" = "arm64" ]]; then
BUILD_TARGET="aarch64-unknown-linux-gnu"
elif [[ "$ARCH" = "aarch64" ]]; then
BUILD_TARGET="aarch64-unknown-linux-gnu"
ARCH="arm64"
fi
if [[ "$ARCH" == "aarch64 ]]; then
ARCH="arm64"
fi
if [[ "$ARCH" = "amd64" ]]; then
BUILD_TARGET="x86_64-unknown-linux-gnu"
elif [[ "$ARCH" = "arm64" ]]; then
BUILD_TARGET="aarch64-unknown-linux-gnu"
else
echo "ERROR Unsupported architecture"
exit 1
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

@jan-auer changed to switch this one

IMG_DEPS: ghcr.io/getsentry/relay-deps:${{ matrix.arch }}
# GITHUB_SHA in pull requests points to the merge commit
IMG_VERSIONED: ghcr.io/getsentry/relay:${{ github.event.pull_request.head.sha || github.sha }}
ARCH: ${{ matrix.arch }}
Copy link
Member Author

Choose a reason for hiding this comment

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

at a glance this looks unused, but it's actually used inside build-docker-image -- I would probably make it an argument to the script instead

- name: Push to ghcr.io
run: |
set -euxo pipefail
docker login --username '${{ github.actor }}' --password '${{ secrets.GITHUB_TOKEN }}' ghcr.io
Copy link
Member Author

Choose a reason for hiding this comment

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

this will fail for external contributors -- you'll probably want to gate this somehow on that

llvm-toolset-7.0-clang-devel \
&& yum clean all \
&& rm -rf /var/cache/yum \
&& ln -s /usr/bin/cmake3 /usr/bin/cmake
Copy link
Member Author

Choose a reason for hiding this comment

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

typically /usr/bin is managed by the package manager, this should be a symlink to /usr/local/bin/cmake probably

Comment on lines +8 to +17
ENV \
RELAY_UID=10001 \
RELAY_GID=10001

# Create a new user and group with fixed uid/gid
RUN groupadd --system relay --gid $RELAY_GID \
&& useradd --system --gid relay --uid $RELAY_UID relay

RUN mkdir /work /etc/relay \
&& chown relay:relay /work /etc/relay
Copy link
Member Author

Choose a reason for hiding this comment

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

not necessary for this PR, but this is much easier to do with USER (and then not needing gosu at all)

IMG_VERSIONED=${IMG_VERSIONED:-"relay:latest"}

# Build a builder image with all the depdendencies.
args=(--progress auto)
Copy link
Member Author

Choose a reason for hiding this comment

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

shouldn't be necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

it fails locally for me, when the args is empty

./scripts/build-docker-image.sh: line 32: args[@]: unbound variable

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, ancient macos bash -- you might be able to use declare -a args

Copy link
Member Author

Choose a reason for hiding this comment

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

or put the real args into the array


# Build the binary inside of the builder image.
docker run \
-v "$(pwd):/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.

$(pwd) => $PWD (var lookup is free compared to a subshell and subprocess)

I also like to be explicit and use --volume and state whether it's :ro or :rw (I don't even remember the default)

Comment on lines 45 to 48
# Fix permissions for shared directories
USER_ID=$(id -u)
GROUP_ID=$(id -g)
sudo chown -R "${USER_ID}:${GROUP_ID}" target/
Copy link
Member Author

Choose a reason for hiding this comment

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

better: run the container with --user and then you don't need to do this. or utilize docker cp

@jan-auer jan-auer merged commit 13cc9e5 into master Feb 10, 2023
@jan-auer jan-auer deleted the asottile-relay-multiarch branch February 10, 2023 09:29
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