-
Notifications
You must be signed in to change notification settings - Fork 69
campaigns: add and use volume mounts by default on Intel macOS #412
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
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
f32ea10
Initial refactor of workspace concerns.
LawnGnome fe2798c
More WIP.
LawnGnome c989ec0
More WIP.
LawnGnome fadf6f3
Add workflow for building the Docker image.
LawnGnome dcde796
First crack at a CHANGELOG.
LawnGnome 29bf3f6
Fix test issue.
LawnGnome 6bad0e4
Handle potential nil pointer in Files.
LawnGnome e8e127e
Switch default on macOS.
LawnGnome 946d9bb
Add initial workspace tests.
LawnGnome d937be1
Flesh out volume workspace tests.
LawnGnome 524e7e8
Fix comments.
LawnGnome c57bbeb
Temporary enable build on all pushes for testing.
LawnGnome 7ab154b
Fix username.
LawnGnome e74781f
Replace the canned Action with a script.
LawnGnome 59ee60b
Run on Ubuntu 20.04.
LawnGnome 201b120
Use text mode when logging in.
LawnGnome 2779612
Only build the Docker image on tag push.
LawnGnome cd7d70f
Multiplatform experimentation, part one.
LawnGnome baf2e90
Multiplatform experimentation, part _n_.
LawnGnome c372daf
More multiarch.
LawnGnome 0baabff
More multiarch.
LawnGnome 0f3bf81
More multiarch.
LawnGnome ef9ef4b
More multiarch.
LawnGnome 0451369
More multiarch.
LawnGnome 1c64e5a
Improve docs.
LawnGnome 1cf0927
Also push the README to Docker Hub.
LawnGnome e47c233
Fix README.
LawnGnome 72c8aa9
Revert to only updating the image on tags.
LawnGnome f3ddce4
Add more docs.
LawnGnome 0de0d79
Only enable volume workspace on x86-64 for now.
LawnGnome f184d7c
Improve workspace dependent Docker image handling.
LawnGnome 7027d7d
Update CHANGELOG.md
LawnGnome 0057a57
Update DEVELOPMENT.md
LawnGnome 5d6ea25
Update internal/api/mock/mock.go
LawnGnome 21a684d
Move directory creation behind exists check.
LawnGnome f318d6c
Rename test function.
LawnGnome ab3468a
Simplify test.
LawnGnome 9f830c7
Make Files private.
LawnGnome 71559c9
Remove Prepare from Workspace interface.
LawnGnome 155e213
Unify repo fetching into a single type.
LawnGnome 0c2fb66
Remove unused API mock functionality.
LawnGnome f1a5666
Fix Windows compatibility.
LawnGnome 9e330c1
temp ci hackery
LawnGnome 17f7c2c
more ci fuckery
LawnGnome 4c81744
revert ci fuckery
LawnGnome df126e1
Add PR to CHANGELOG.
LawnGnome 605b0f1
Remove unused dependency.
LawnGnome 7479a24
Update CHANGELOG.md
LawnGnome ffe31df
Update cmd/src/campaigns_common.go
LawnGnome b7d5505
Use filepath.Join.
LawnGnome 203868d
Add documentation.
LawnGnome 13b0eed
Migrate fetch utility functions to the right place.
LawnGnome File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # For more information, refer to the "Dependent Docker images" section of | ||
| # DEVELOPMENT.md. | ||
| name: Publish Docker image dependencies | ||
|
|
||
| # We only want to build on releases; this condition is 100% stolen from the | ||
| # goreleaser action. | ||
| on: | ||
| push: | ||
| tags: | ||
| - "*" | ||
| - "!latest" | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-20.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v2 | ||
|
|
||
| # We need buildx to be able to build a multi-architecture image. | ||
| - name: Set up Docker buildx | ||
| uses: docker/setup-buildx-action@v1 | ||
|
|
||
| # We also need QEMU, since this is running on an AMD64 host and we want to | ||
| # build ARM64 images. | ||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v1 | ||
| with: | ||
| platforms: arm64 | ||
|
|
||
| - run: ./docker/campaign-volume-workspace/push.py -d ./docker/campaign-volume-workspace/Dockerfile -i sourcegraph/src-campaign-volume-workspace -p linux/amd64,linux/arm64,linux/386 | ||
| env: | ||
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
| DOCKER_USERNAME: sourcegraphci | ||
|
|
||
| - name: Update Docker Hub description | ||
| uses: peter-evans/dockerhub-description@v2 | ||
| with: | ||
| username: sourcegraphci | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| repository: sourcegraph/src-campaign-volume-workspace | ||
| readme-filepath: ./docker/campaign-volume-workspace/README.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # This Dockerfile builds the sourcegraph/src-campaign-volume-workspace image | ||
| # that we use to run curl, git, and unzip against a Docker volume when using | ||
| # the volume workspace. | ||
|
|
||
| FROM alpine:3.12.3 | ||
|
|
||
| # Note that we have to configure git's user.email and user.name settings to | ||
| # avoid issues when committing changes. These values are not used when creating | ||
| # changesets, since we only extract the diff from the container and not a full | ||
| # patch, but need to be set to avoid git erroring out. | ||
| RUN apk add --update curl git unzip && \ | ||
| git config --global user.email campaigns@sourcegraph.com && \ | ||
| git config --global user.name 'Sourcegraph Campaigns' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # `src` volume workspace base image | ||
|
|
||
| Sourcegraph `src` executes campaigns using either a bind or volume workspace. In the latter case (which is the default on macOS), this utility image is used to initialise the volume workspace within Docker, and then to extract the diff used when creating the changeset. | ||
|
|
||
| This image is based on Alpine, and adds the tools we need: curl, git, and unzip. | ||
|
|
||
| For more information, please refer to the [`src-cli` repository](https://github.com/sourcegraph/src-cli/tree/main/docker/campaign-volume-workspace). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # This is a very simple script to build and push the Docker image used by the | ||
| # Docker volume workspace driver. It's normally run from the "Publish Docker | ||
| # image dependencies" GitHub Action, but can be run locally if necessary. | ||
| # | ||
| # This script requires Python 3.8 or later, and Docker 19.03 (for buildx). You | ||
| # are strongly encouraged to use Black to format this file after modifying it. | ||
| # | ||
| # To run it locally, you'll need to be logged into Docker Hub, and create an | ||
| # image in a namespace that you have access to. For example, if your username is | ||
| # "alice", you could build and push the image as follows: | ||
| # | ||
| # $ ./push.py -d Dockerfile -i alice/src-campaign-volume-workspace | ||
| # | ||
| # By default, only the "latest" tag will be built and pushed. The script refers | ||
| # to the HEAD ref given to it, either via $GITHUB_REF or the -r argument. If | ||
| # this is in the form refs/tags/X.Y.Z, then we'll also push X, X.Y, and X.Y.Z | ||
| # tags. | ||
| # | ||
| # Finally, if you have your environment configured to allow multi-architecture | ||
| # builds with docker buildx, you can provide a --platform argument that will be | ||
| # passed through verbatim to docker buildx build. (This is how we build ARM64 | ||
| # builds in our CI.) For example, you could build ARM64 and AMD64 images with: | ||
| # | ||
| # $ ./push.py --platform linux/arm64,linux/amd64 ... | ||
| # | ||
| # For this to work, you will need a builder with the relevant platforms enabled. | ||
| # More instructions on this can be found at | ||
| # https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images. | ||
|
|
||
| import argparse | ||
| import itertools | ||
| import os | ||
| import subprocess | ||
|
|
||
| from typing import BinaryIO, Optional, Sequence | ||
|
|
||
|
|
||
| def calculate_tags(ref: str) -> Sequence[str]: | ||
| # The tags always include latest. | ||
| tags = ["latest"] | ||
|
|
||
| # If the ref is a tag ref, then we should parse the version out and add each | ||
| # component to our tag list: for example, for X.Y.Z, we want tags X, X.Y, | ||
| # and X.Y.Z. | ||
| if ref.startswith("refs/tags/"): | ||
| tags.extend( | ||
| [ | ||
| # Join the version components back into a string. | ||
| ".".join(vc) | ||
| for vc in itertools.accumulate( | ||
| # Split the version string into its components. | ||
| ref.split("/", 2)[2].split("."), | ||
| # Accumulate each component we've seen into a new list | ||
| # entry. | ||
| lambda vlist, v: vlist + [v], | ||
| initial=[], | ||
| ) | ||
| # We also get the initial value, so we need to skip that. | ||
| if len(vc) > 0 | ||
| ] | ||
| ) | ||
|
|
||
| return tags | ||
|
|
||
|
|
||
| def docker_build( | ||
| dockerfile: BinaryIO, platform: Optional[str], image: str, tags: Sequence[str] | ||
| ): | ||
| args = ["docker", "buildx", "build", "--push"] | ||
|
|
||
| for tag in tags: | ||
| args.extend(["-t", f"{image}:{tag}"]) | ||
|
|
||
| if platform is not None: | ||
| args.extend(["--platform", platform]) | ||
|
|
||
| # Since we provide the Dockerfile via stdin, we don't need to provide it | ||
| # here. (Doing so means that we don't carry an unncessary context into the | ||
| # builder.) | ||
| args.append("-") | ||
|
|
||
| run(args, stdin=dockerfile) | ||
|
|
||
|
|
||
| def docker_login(username: str, password: str): | ||
| run( | ||
| ["docker", "login", f"-u={username}", "--password-stdin"], | ||
| input=password, | ||
| text=True, | ||
| ) | ||
|
|
||
|
|
||
| def run(args: Sequence[str], /, **kwargs) -> subprocess.CompletedProcess: | ||
| print(f"+ {' '.join(args)}") | ||
| return subprocess.run(args, check=True, **kwargs) | ||
|
|
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "-d", "--dockerfile", required=True, help="the Dockerfile to build" | ||
| ) | ||
| parser.add_argument("-i", "--image", required=True, help="Docker image to push") | ||
| parser.add_argument( | ||
| "-p", | ||
| "--platform", | ||
| help="platforms to build using docker buildx (if omitted, the default will be used)", | ||
| ) | ||
| parser.add_argument( | ||
| "-r", | ||
| "--ref", | ||
| default=os.environ.get("GITHUB_REF"), | ||
| help="current ref in refs/heads/... or refs/tags/... form", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| tags = calculate_tags(args.ref) | ||
| print(f"will push tags: {', '.join(tags)}") | ||
|
|
||
| print("logging into Docker Hub") | ||
| try: | ||
| docker_login(os.environ["DOCKER_USERNAME"], os.environ["DOCKER_PASSWORD"]) | ||
| except KeyError as e: | ||
| print(f"error retrieving environment variables: {e}") | ||
| raise | ||
|
|
||
| print("building and pushing image") | ||
| docker_build(open(args.dockerfile, "rb"), args.platform, args.image, tags) | ||
|
|
||
| print("success!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.