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

Run docker on forked pull requests #1450

Merged
merged 22 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Publish Docker Image

on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
reason:
Expand All @@ -12,7 +15,11 @@ on:
jobs:
ghcr_build_and_push:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.inputs.reason != ''

permissions:
contents: read
packages: write

strategy:
matrix:
image: ["app", "evaluation", "sandbox"]
Expand All @@ -28,16 +35,25 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3

- name: Log-in to ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Delete huge unnecessary tools folder
run: rm -rf /opt/hostedtoolcache

- name: Build and push ${{ matrix.image }}
if: github.event.pull_request.head.repo.full_name == github.repository
run: |
./containers/build.sh ${{ matrix.image }} ${{ github.repository_owner }} --push

- name: Build ${{ matrix.image }}
if: github.event.pull_request.head.repo.full_name != github.repository
run: |
ORG_NAME=$(echo "${{ github.repository }}" | tr '[A-Z]' '[a-z]' | cut -d '/' -f 1)
./containers/build.sh ${{ matrix.image }} $ORG_NAME --push
./containers/build.sh ${{ matrix.image }} ${{ github.repository_owner }}

docker_build_success:
name: Docker Build Success
Expand Down
3 changes: 2 additions & 1 deletion containers/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if [[ -n "$org_name" ]]; then
DOCKER_ORG="$org_name"
fi
DOCKER_REPOSITORY=$DOCKER_REGISTRY/$DOCKER_ORG/$DOCKER_IMAGE
DOCKER_REPOSITORY=${DOCKER_REPOSITORY,,} # lowercase
echo "Repo: $DOCKER_REPOSITORY"
echo "Base dir: $DOCKER_BASE_DIR"

Expand All @@ -53,12 +54,12 @@ for tag in ${tags[@]}; do
done
if [[ $push -eq 1 ]]; then
args+=" --push"
args+=" --cache-to=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag,mode=max"
fi

docker buildx build \
$args \
--build-arg OPEN_DEVIN_BUILD_VERSION=$OPEN_DEVIN_BUILD_VERSION \
--cache-to=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag,mode=max \
--cache-from=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag \
--cache-from=type=registry,ref=$DOCKER_REPOSITORY:$cache_tag_base-main \
--platform linux/amd64,linux/arm64 \
Expand Down