From 99a77c732a013761584a865fdc9b2419748a05b1 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Sun, 23 Apr 2023 23:15:30 +0200 Subject: [PATCH 01/15] initial cleanup of github workflows --- .github/workflows/auto_format.yml | 23 --- .../{benchmark.yml => benchmarks.yml} | 22 +-- .github/workflows/ci.yml | 8 +- .github/workflows/docker-ci.yml | 148 ++++++++++++++++ .github/workflows/docker-image.yml | 21 --- .github/workflows/docker-release.yml | 167 ++++++++++++++++++ .github/workflows/dockerhub-imagepush.yml | 31 ---- ...entation.yml => documentation-release.yml} | 16 +- .github/workflows/pr-label.yml | 8 +- .github/workflows/sponsors_readme.yml | 5 +- 10 files changed, 350 insertions(+), 99 deletions(-) delete mode 100644 .github/workflows/auto_format.yml rename .github/workflows/{benchmark.yml => benchmarks.yml} (60%) create mode 100644 .github/workflows/docker-ci.yml delete mode 100644 .github/workflows/docker-image.yml create mode 100644 .github/workflows/docker-release.yml delete mode 100644 .github/workflows/dockerhub-imagepush.yml rename .github/workflows/{documentation.yml => documentation-release.yml} (65%) diff --git a/.github/workflows/auto_format.yml b/.github/workflows/auto_format.yml deleted file mode 100644 index c33cd39755d5..000000000000 --- a/.github/workflows/auto_format.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: auto-format -on: pull_request -jobs: - format: - runs-on: ubuntu-latest - steps: - - name: Checkout PR branch - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - - name: autopep8 - uses: peter-evans/autopep8@v1 - with: - args: --exit-code --recursive --in-place --aggressive --aggressive . - - name: Check for modified files - id: git-check - run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_ENV - - name: Push changes - if: steps.git-check.outputs.modified == 'true' - run: | - git config --global user.name 'Torantulino' - git config --global user.email 'toran.richards@gmail.com' - git remote set diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmarks.yml similarity index 60% rename from .github/workflows/benchmark.yml rename to .github/workflows/benchmarks.yml index 0d9822f70530..272fca17bdcb 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmarks.yml @@ -1,4 +1,4 @@ -name: benchmark +name: Run Benchmarks on: workflow_dispatch: @@ -6,26 +6,26 @@ on: jobs: build: runs-on: ubuntu-latest - environment: benchmark - strategy: - matrix: - python-version: ['3.10', '3.11'] + + env: + python-version: '3.10' steps: - - name: Check out repository + - name: Checkout repository uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + - name: Set up Python ${{ env.python-version }} + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ env.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt + - name: benchmark - run: | - python benchmark/benchmark_entrepreneur_gpt_with_undecisive_user.py env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + python benchmark/benchmark_entrepreneur_gpt_with_undecisive_user.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 780db14fc6c5..995087ebecf5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,12 +2,12 @@ name: Python CI on: push: - branches: [master] + branches: [ master ] pull_request: - branches: [master] + branches: [ master ] concurrency: - group: ${{ format('ci-{0}', format('pr-{0}', github.event.pull_request.number) || github.sha) }} + group: ${{ format('ci-{0}', github.head_ref && format('pr-{0}', github.event.pull_request.number) || github.sha) }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: @@ -17,7 +17,7 @@ jobs: min-python-version: "3.10" steps: - - name: Check out repository + - name: Checkout repository uses: actions/checkout@v3 - name: Set up Python ${{ env.min-python-version }} diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml new file mode 100644 index 000000000000..cd6a35144261 --- /dev/null +++ b/.github/workflows/docker-ci.yml @@ -0,0 +1,148 @@ +name: Docker CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +concurrency: + group: ${{ format('docker-ci-{0}', github.head_ref && format('pr-{0}', github.event.pull_request.number) || github.sha) }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # slashes are not allowed in image tags, but can appear in git branch or tag names + - id: sanitize_tag + name: Sanitize image tag + run: echo tag=${raw_tag//\//-} >> $GITHUB_OUTPUT + env: + raw_tag: ${{ github.ref_name }} + + - id: build + name: Build image + uses: docker/build-push-action@v3 + with: + load: true # save to docker images + + # cache layers in GitHub Actions cache to speed up builds + cache-from: 'type=gha' + cache-to: type=gha,mode=max + + - name: Generate build report + env: + prod_branch: stable + dev_branch: master + base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'stable' && 'master' || 'stable' }} + current_ref: ${{ github.ref_name }} + compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} + + commit_hash: ${{ github.event.after }} + head_compare_url: ${{ github.event.compare }} + new_commits_json: ${{ toJSON(github.event.commits) }} + + github_context_json: ${{ toJSON(github) }} + job_env_json: ${{ toJSON(env) }} + vars_json: ${{ toJSON(vars) }} + + run: | + meta=$(docker image inspect $IMAGE_NAME | jq '.[0]') + + ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) + + cat << MarkdownHERE >> $GITHUB_STEP_SUMMARY + # Docker Build summary 🔨 + + **Source:** ${{ github.ref_type }} \`$current_ref\` -> [${{ github.repository }}@\`${commit_hash:0:7}\`](${{ github.event.head_commit.url }}) + + **Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB + + ## Image details + + **Tags:** + $(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) + +
+

Layers

+ + | Age | Size | Created by instruction | + | --------- | ------ | ---------------------- | + $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ + | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ + | cut -f-3 `# yeet Comment column`\ + | sed 's/ ago//' `# fix Layer age`\ + | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | column -t -s$'\t' -o' | ' `# align columns and add separator`\ + | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) +
+ +
+

ENV

+ + | Variable | Value | + | -------- | -------- | + $(jq -r \ + '.Config.Env + | map( + split("=") + | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" + ) + | map("| \(.) |") + | .[]' <<< $meta + ) +
+ +
+ Raw metadata + + \`\`\`JSON + $meta + \`\`\` +
+ + ## Build details + **Build trigger:** ${{ github.event.forced && '☢️ forced' || '' }} ${{ github.event_name }} \`${{ github.event.ref }}\` + +
+ github context + + \`\`\`JSON + $github_context_json + \`\`\` +
+ + ### Source + **HEAD:** [${{ github.repository }}@\`${commit_hash:0:7}\`](${{ github.event.head_commit.url }}) on ${{ github.ref_type }} [$current_ref]($ref_compare_url) + + **Diff with previous HEAD:** $head_compare_url + + #### New commits + $(jq -r 'map([ + "**Commit [`\(.id[0:7])`](\(.url)) by \(if .author.username then "@"+.author.username else .author.name end):**", + .message, + (if .committer.name != .author.name then "\n> **Committer:** \(.committer.name) <\(.committer.email)>" else "" end), + "**Timestamp:** \(.timestamp)" + ] | map("> \(.)\n") | join("")) | join("\n")' <<< $new_commits_json) + + ### Job environment + + #### \`vars\` context: + \`\`\`JSON + $vars_json + \`\`\` + + #### \`env\` context: + \`\`\`JSON + $job_env_json + \`\`\` + + MarkdownHERE + continue-on-error: true diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 2fcf6401efbf..000000000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Docker Image CI - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] -concurrency: - group: ${{ format('docker-ci-{0}', github.event.pull_request.number || github.sha) }} - cancel-in-progress: true - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag autogpt:$(date +%s) diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 000000000000..28cfb44a1632 --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,167 @@ +name: Docker Release + +on: + release: + types: [ published, edited ] + + workflow_dispatch: + inputs: + no_cache: + type: boolean + description: 'Build from scratch, without using cached layers' + +env: + IMAGE_NAME: auto-gpt + DEPLOY_IMAGE_NAME: ${{ secrets.DOCKER_USER }}/auto-gpt + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to Docker hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # slashes are not allowed in image tags, but can appear in git branch or tag names + - id: sanitize_tag + name: Sanitize image tag + run: echo tag=${raw_tag//\//-} >> $GITHUB_OUTPUT + env: + raw_tag: ${{ github.ref_name }} + + - id: build + name: Build image + uses: docker/build-push-action@v3 + with: + load: true # save to docker images + # push: true # TODO: uncomment when this issue is fixed: https://github.com/moby/buildkit/issues/1555 + tags: > + ${{ env.IMAGE_NAME }}, + ${{ env.DEPLOY_IMAGE_NAME }}:latest, + ${{ env.DEPLOY_IMAGE_NAME }}:${{ steps.sanitize_tag.outputs.tag }} + + # cache layers in GitHub Actions cache to speed up builds + cache-from: ${{ !inputs.no_cache && 'type=gha' || '' }} + cache-to: type=gha,mode=max + + - name: Push image to Docker Hub + run: docker push --all-tags ${{ env.DEPLOY_IMAGE_NAME }} + + - name: Generate build report + env: + prod_branch: stable + dev_branch: master + base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'stable' && 'master' || 'stable' }} + current_ref: ${{ github.ref_name }} + source_url: ${{ format('{0}/tree/{1}', github.event.repository.url, github.event.release && github.event.release.tag_name || github.sha) }} + compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} + + github_context_json: ${{ toJSON(github) }} + job_env_json: ${{ toJSON(env) }} + vars_json: ${{ toJSON(vars) }} + + run: | + meta=$(docker image inspect $IMAGE_NAME | jq '.[0]') + + ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) + + cat << MarkdownHERE >> $GITHUB_STEP_SUMMARY + # Docker Release Build summary 🚀🔨 + + **Source:** ${{ github.ref_type }} \`$current_ref\` -> [${{ github.repository }}@\`${commit_hash:0:7}\`]($source_url) + + **Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB + + ## Image details + + **Tags:** + $(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) + +
+

Layers

+ + | Age | Size | Created by instruction | + | --------- | ------ | ---------------------- | + $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ + | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ + | cut -f-3 `# yeet Comment column`\ + | sed 's/ ago//' `# fix Layer age`\ + | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | column -t -s$'\t' -o' | ' `# align columns and add separator`\ + | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) +
+ +
+

ENV

+ + | Variable | Value | + | -------- | -------- | + $(jq -r \ + '.Config.Env + | map( + split("=") + | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" + ) + | map("| \(.) |") + | .[]' <<< $meta + ) +
+ +
+ Raw metadata + + \`\`\`JSON + $meta + \`\`\` +
+ + ## Build details + **Build trigger:** ${{ github.event_name }} \`${{ github.event.ref }}\` + + | Parameter | Value | + | -------------- | ------------ | + | \`no_cache\` | \`${{ inputs.no_cache }}\` | + +
+ github context + + \`\`\`JSON + $github_context_json + \`\`\` +
+ + ### Source + **HEAD:** [${{ github.repository }}@\`${commit_hash:0:7}\`]($source_url) on ${{ github.ref_type }} [$current_ref]($ref_compare_url) + + **Diff with previous HEAD:** $head_compare_url + + #### New commits + $(jq -r 'map([ + "**Commit [`\(.id[0:7])`](\(.url)) by \(if .author.username then "@"+.author.username else .author.name end):**", + .message, + (if .committer.name != .author.name then "\n> **Committer:** \(.committer.name) <\(.committer.email)>" else "" end), + "**Timestamp:** \(.timestamp)" + ] | map("> \(.)\n") | join("")) | join("\n")' <<< $new_commits_json) + + ### Job environment + + #### \`vars\` context: + \`\`\`JSON + $vars_json + \`\`\` + + #### \`env\` context: + \`\`\`JSON + $job_env_json + \`\`\` + + MarkdownHERE + continue-on-error: true diff --git a/.github/workflows/dockerhub-imagepush.yml b/.github/workflows/dockerhub-imagepush.yml deleted file mode 100644 index 165f62658daa..000000000000 --- a/.github/workflows/dockerhub-imagepush.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Push Docker Image on Release - -on: - release: - types: [published,edited] - -jobs: - - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Log in to Docker hub - env: - DOCKER_USER: ${{secrets.DOCKER_USER}} - DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} - run: | - docker login -u $DOCKER_USER -p $DOCKER_PASSWORD - - name: Build the Docker image - run: | - tag_v=$(git describe --tags $(git rev-list --tags --max-count=1)) - tag=$(echo $tag_v | sed 's/v//') - docker build . --file Dockerfile --tag ${{secrets.DOCKER_USER}}/auto-gpt:${tag} - - name: Docker Push - run: | - tag_v2=$(git describe --tags $(git rev-list --tags --max-count=1)) - tag2=$(echo $tag_v | sed 's/v//') - docker push ${{secrets.DOCKER_USER}}/auto-gpt:${tag2} - diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation-release.yml similarity index 65% rename from .github/workflows/documentation.yml rename to .github/workflows/documentation-release.yml index 7a7fd784a630..ef97e1e435ce 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation-release.yml @@ -13,17 +13,25 @@ on: permissions: contents: write + jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Python 3 + uses: actions/setup-python@v4 with: python-version: 3.x - - uses: actions/cache@v2 + + - name: Set up workflow cache + uses: actions/cache@v3 with: key: ${{ github.ref }} path: .cache - - run: pip install mkdocs-material + + - run: pip install mkdocs-material + - run: mkdocs gh-deploy --force diff --git a/.github/workflows/pr-label.yml b/.github/workflows/pr-label.yml index f1b200b0b387..25eafb003388 100644 --- a/.github/workflows/pr-label.yml +++ b/.github/workflows/pr-label.yml @@ -1,4 +1,5 @@ name: "Pull Request auto-label" + on: # So that PRs touching the same files as the push are updated push: @@ -6,7 +7,8 @@ on: # We recommend `pull_request_target` so that github secrets are available. # In `pull_request` we wouldn't be able to change labels of fork PRs pull_request_target: - types: [opened, synchronize] + types: [ opened, synchronize ] + concurrency: group: ${{ format('pr-label-{0}', github.event.pull_request.number || github.sha) }} cancel-in-progress: true @@ -34,7 +36,7 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - uses: codelytv/pr-size-labeler@v1.7.0 + - uses: codelytv/pr-size-labeler@v1 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} s_label: "size/s" @@ -44,5 +46,3 @@ jobs: l_label: "size/l" l_max_size: "200" xl_label: "size/xl" - fail_if_xl: "false" - github_api_url: "api.github.com" diff --git a/.github/workflows/sponsors_readme.yml b/.github/workflows/sponsors_readme.yml index fffdbd4dabf9..7e51a4f820b1 100644 --- a/.github/workflows/sponsors_readme.yml +++ b/.github/workflows/sponsors_readme.yml @@ -1,14 +1,17 @@ name: Generate Sponsors README + on: workflow_dispatch: schedule: - cron: '0 */12 * * *' + jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout 🛎️ - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Generate Sponsors 💖 uses: JamesIves/github-sponsors-readme-action@v1 with: From 58f779845b64987b28f0dfcb77b0ca7f3700fec2 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Sun, 23 Apr 2023 23:24:24 +0200 Subject: [PATCH 02/15] only run pr-label workflow on push to master --- .github/workflows/pr-label.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-label.yml b/.github/workflows/pr-label.yml index 25eafb003388..4213a4150d80 100644 --- a/.github/workflows/pr-label.yml +++ b/.github/workflows/pr-label.yml @@ -3,6 +3,7 @@ name: "Pull Request auto-label" on: # So that PRs touching the same files as the push are updated push: + branches: [ master ] # So that the `dirtyLabel` is removed if conflicts are resolve # We recommend `pull_request_target` so that github secrets are available. # In `pull_request` we wouldn't be able to change labels of fork PRs From 435a346ee4a0dc355cdd3ea752b7d97e84d0fe49 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Sun, 23 Apr 2023 23:58:46 +0200 Subject: [PATCH 03/15] move docker ci/release summaries to scripts --- .github/workflows/docker-ci.yml | 113 ++---------------- .github/workflows/docker-release.yml | 107 ++--------------- .../workflows/scripts/docker-ci-summary.sh | 93 ++++++++++++++ .../scripts/docker-release-summary.sh | 83 +++++++++++++ 4 files changed, 197 insertions(+), 199 deletions(-) create mode 100644 .github/workflows/scripts/docker-ci-summary.sh create mode 100644 .github/workflows/scripts/docker-release-summary.sh diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index cd6a35144261..9299ac3b2fe9 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -20,129 +20,38 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - # slashes are not allowed in image tags, but can appear in git branch or tag names - - id: sanitize_tag - name: Sanitize image tag - run: echo tag=${raw_tag//\//-} >> $GITHUB_OUTPUT - env: - raw_tag: ${{ github.ref_name }} - - id: build name: Build image uses: docker/build-push-action@v3 with: load: true # save to docker images - # cache layers in GitHub Actions cache to speed up builds cache-from: 'type=gha' cache-to: type=gha,mode=max - name: Generate build report env: + event_name: ${{ github.event_name }} + event_ref: ${{ github.event.ref }} + event_ref_type: ${{ github.event.ref}} + prod_branch: stable dev_branch: master + repository: ${{ github.repository }} base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'stable' && 'master' || 'stable' }} - current_ref: ${{ github.ref_name }} - compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} + current_ref: ${{ github.ref_name }} commit_hash: ${{ github.event.after }} + source_url: ${{ github.event.head_commit.url }} + push_forced_label: ${{ github.event.forced && '☢️ forced' || '' }} + head_compare_url: ${{ github.event.compare }} new_commits_json: ${{ toJSON(github.event.commits) }} + compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} github_context_json: ${{ toJSON(github) }} job_env_json: ${{ toJSON(env) }} vars_json: ${{ toJSON(vars) }} - run: | - meta=$(docker image inspect $IMAGE_NAME | jq '.[0]') - - ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) - - cat << MarkdownHERE >> $GITHUB_STEP_SUMMARY - # Docker Build summary 🔨 - - **Source:** ${{ github.ref_type }} \`$current_ref\` -> [${{ github.repository }}@\`${commit_hash:0:7}\`](${{ github.event.head_commit.url }}) - - **Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB - - ## Image details - - **Tags:** - $(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) - -
-

Layers

- - | Age | Size | Created by instruction | - | --------- | ------ | ---------------------- | - $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ - | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ - | cut -f-3 `# yeet Comment column`\ - | sed 's/ ago//' `# fix Layer age`\ - | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ - | column -t -s$'\t' -o' | ' `# align columns and add separator`\ - | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) -
- -
-

ENV

- - | Variable | Value | - | -------- | -------- | - $(jq -r \ - '.Config.Env - | map( - split("=") - | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" - ) - | map("| \(.) |") - | .[]' <<< $meta - ) -
- -
- Raw metadata - - \`\`\`JSON - $meta - \`\`\` -
- - ## Build details - **Build trigger:** ${{ github.event.forced && '☢️ forced' || '' }} ${{ github.event_name }} \`${{ github.event.ref }}\` - -
- github context - - \`\`\`JSON - $github_context_json - \`\`\` -
- - ### Source - **HEAD:** [${{ github.repository }}@\`${commit_hash:0:7}\`](${{ github.event.head_commit.url }}) on ${{ github.ref_type }} [$current_ref]($ref_compare_url) - - **Diff with previous HEAD:** $head_compare_url - - #### New commits - $(jq -r 'map([ - "**Commit [`\(.id[0:7])`](\(.url)) by \(if .author.username then "@"+.author.username else .author.name end):**", - .message, - (if .committer.name != .author.name then "\n> **Committer:** \(.committer.name) <\(.committer.email)>" else "" end), - "**Timestamp:** \(.timestamp)" - ] | map("> \(.)\n") | join("")) | join("\n")' <<< $new_commits_json) - - ### Job environment - - #### \`vars\` context: - \`\`\`JSON - $vars_json - \`\`\` - - #### \`env\` context: - \`\`\`JSON - $job_env_json - \`\`\` - - MarkdownHERE + run: .github/workflows/scripts/docker-ci-summary.sh >> $GITHUB_STEP_SUMMARY continue-on-error: true diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 28cfb44a1632..7c52ebc60360 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -57,111 +57,24 @@ jobs: - name: Generate build report env: + event_name: ${{ github.event_name }} + event_ref: ${{ github.event.ref }} + event_ref_type: ${{ github.event.ref}} + inputs_no_cache: ${{ inputs.no_cache }} + prod_branch: stable dev_branch: master + repository: ${{ github.repository }} base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'stable' && 'master' || 'stable' }} + + ref_type: ${{ github.ref_type }} current_ref: ${{ github.ref_name }} + commit_hash: ${{ github.sha }} source_url: ${{ format('{0}/tree/{1}', github.event.repository.url, github.event.release && github.event.release.tag_name || github.sha) }} - compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} github_context_json: ${{ toJSON(github) }} job_env_json: ${{ toJSON(env) }} vars_json: ${{ toJSON(vars) }} - run: | - meta=$(docker image inspect $IMAGE_NAME | jq '.[0]') - - ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) - - cat << MarkdownHERE >> $GITHUB_STEP_SUMMARY - # Docker Release Build summary 🚀🔨 - - **Source:** ${{ github.ref_type }} \`$current_ref\` -> [${{ github.repository }}@\`${commit_hash:0:7}\`]($source_url) - - **Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB - - ## Image details - - **Tags:** - $(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) - -
-

Layers

- - | Age | Size | Created by instruction | - | --------- | ------ | ---------------------- | - $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ - | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ - | cut -f-3 `# yeet Comment column`\ - | sed 's/ ago//' `# fix Layer age`\ - | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ - | column -t -s$'\t' -o' | ' `# align columns and add separator`\ - | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) -
- -
-

ENV

- - | Variable | Value | - | -------- | -------- | - $(jq -r \ - '.Config.Env - | map( - split("=") - | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" - ) - | map("| \(.) |") - | .[]' <<< $meta - ) -
- -
- Raw metadata - - \`\`\`JSON - $meta - \`\`\` -
- - ## Build details - **Build trigger:** ${{ github.event_name }} \`${{ github.event.ref }}\` - - | Parameter | Value | - | -------------- | ------------ | - | \`no_cache\` | \`${{ inputs.no_cache }}\` | - -
- github context - - \`\`\`JSON - $github_context_json - \`\`\` -
- - ### Source - **HEAD:** [${{ github.repository }}@\`${commit_hash:0:7}\`]($source_url) on ${{ github.ref_type }} [$current_ref]($ref_compare_url) - - **Diff with previous HEAD:** $head_compare_url - - #### New commits - $(jq -r 'map([ - "**Commit [`\(.id[0:7])`](\(.url)) by \(if .author.username then "@"+.author.username else .author.name end):**", - .message, - (if .committer.name != .author.name then "\n> **Committer:** \(.committer.name) <\(.committer.email)>" else "" end), - "**Timestamp:** \(.timestamp)" - ] | map("> \(.)\n") | join("")) | join("\n")' <<< $new_commits_json) - - ### Job environment - - #### \`vars\` context: - \`\`\`JSON - $vars_json - \`\`\` - - #### \`env\` context: - \`\`\`JSON - $job_env_json - \`\`\` - - MarkdownHERE + run: .github/workflows/scripts/docker-release-summary.sh >> $GITHUB_STEP_SUMMARY continue-on-error: true diff --git a/.github/workflows/scripts/docker-ci-summary.sh b/.github/workflows/scripts/docker-ci-summary.sh new file mode 100644 index 000000000000..fbed1975213c --- /dev/null +++ b/.github/workflows/scripts/docker-ci-summary.sh @@ -0,0 +1,93 @@ +#!/bin/bash +meta=$(docker image inspect "$IMAGE_NAME" | jq '.[0]') +ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) + +EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + +cat << $EOF +# Docker Build summary 🔨 + +**Source:** branch \`$current_ref\` -> [$repository@\`${commit_hash:0:7}\`]($source_url) + +**Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB + +## Image details + +**Tags:** +$(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) + +
+

Layers

+ +| Age | Size | Created by instruction | +| --------- | ------ | ---------------------- | +$(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ + | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ + | cut -f-3 `# yeet Comment column`\ + | sed 's/ ago//' `# fix Layer age`\ + | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | column -t -s$'\t' -o' | ' `# align columns and add separator`\ + | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) +
+ +
+

ENV

+ +| Variable | Value | +| -------- | -------- | +$(jq -r \ + '.Config.Env + | map( + split("=") + | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" + ) + | map("| \(.) |") + | .[]' <<< $meta +) +
+ +
+Raw metadata + +\`\`\`JSON +$meta +\`\`\` +
+ +## Build details +**Build trigger:** $push_forced_label $event_name \`$event_ref\` + +
+github context + +\`\`\`JSON +$github_context_json +\`\`\` +
+ +### Source +**HEAD:** [$repository@\`${commit_hash:0:7}\`]($source_url) on branch [$current_ref]($ref_compare_url) + +**Diff with previous HEAD:** $head_compare_url + +#### New commits +$(jq -r 'map([ + "**Commit [`\(.id[0:7])`](\(.url)) by \(if .author.username then "@"+.author.username else .author.name end):**", + .message, + (if .committer.name != .author.name then "\n> **Committer:** \(.committer.name) <\(.committer.email)>" else "" end), + "**Timestamp:** \(.timestamp)" +] | map("> \(.)\n") | join("")) | join("\n")' <<< $new_commits_json) + +### Job environment + +#### \`vars\` context: +\`\`\`JSON +$vars_json +\`\`\` + +#### \`env\` context: +\`\`\`JSON +$job_env_json +\`\`\` + +$EOF diff --git a/.github/workflows/scripts/docker-release-summary.sh b/.github/workflows/scripts/docker-release-summary.sh new file mode 100644 index 000000000000..52f56228d42b --- /dev/null +++ b/.github/workflows/scripts/docker-release-summary.sh @@ -0,0 +1,83 @@ +#!/bin/bash +meta=$(docker image inspect "$IMAGE_NAME" | jq '.[0]') + +EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + +cat << $EOF +# Docker Release Build summary 🚀🔨 + +**Source:** $ref_type \`$current_ref\` -> [$repository@\`${commit_hash:0:7}\`]($source_url) + +**Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB + +## Image details + +**Tags:** +$(jq -r '.RepoTags | map("* `\(.)`") | join("\n")' <<< $meta) + +
+

Layers

+ +| Age | Size | Created by instruction | +| --------- | ------ | ---------------------- | +$(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.CreatedBy}}\`\t{{.Comment}}" $IMAGE_NAME \ + | grep 'buildkit.dockerfile' `# filter for layers created in this build process`\ + | cut -f-3 `# yeet Comment column`\ + | sed 's/ ago//' `# fix Layer age`\ + | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | column -t -s$'\t' -o' | ' `# align columns and add separator`\ + | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) +
+ +
+

ENV

+ +| Variable | Value | +| -------- | -------- | +$(jq -r \ + '.Config.Env + | map( + split("=") + | "\(.[0]) | `\(.[1] | gsub("\\s+"; " "))`" + ) + | map("| \(.) |") + | .[]' <<< $meta +) +
+ +
+Raw metadata + +\`\`\`JSON +$meta +\`\`\` +
+ +## Build details +**Build trigger:** $event_name \`$event_ref\` + +| Parameter | Value | +| -------------- | ------------ | +| \`no_cache\` | \`$inputs_no_cache\` | + +
+github context + +\`\`\`JSON +$github_context_json +\`\`\` +
+ +### Job environment + +#### \`vars\` context: +\`\`\`JSON +$vars_json +\`\`\` + +#### \`env\` context: +\`\`\`JSON +$job_env_json +\`\`\` + +$EOF From bbae19673d2ce6653edf2be54a98418fa5fb0303 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 00:37:47 +0200 Subject: [PATCH 04/15] add XS label for PR's under 2 lines --- .github/workflows/pr-label.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-label.yml b/.github/workflows/pr-label.yml index 4213a4150d80..d4e9a5e720f0 100644 --- a/.github/workflows/pr-label.yml +++ b/.github/workflows/pr-label.yml @@ -40,10 +40,12 @@ jobs: - uses: codelytv/pr-size-labeler@v1 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - s_label: "size/s" - s_max_size: "10" - m_label: "size/m" - m_max_size: "50" - l_label: "size/l" - l_max_size: "200" - xl_label: "size/xl" + xs_label: 'size/xs' + xs_max_size: 2 + s_label: 'size/s' + s_max_size: 10 + m_label: 'size/m' + m_max_size: 50 + l_label: 'size/l' + l_max_size: 200 + xl_label: 'size/xl' From 4d0e5ce86b83ed07ae70a2b1cb22c92e0ce6fa94 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 01:04:15 +0200 Subject: [PATCH 05/15] draft test job for Docker CI --- .github/workflows/ci.yml | 1 + .github/workflows/docker-ci.yml | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 995087ebecf5..0b2bbde668e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -74,6 +74,7 @@ jobs: pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + - name: Generate coverage report run: | coverage report diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 9299ac3b2fe9..6e6c40bfd9e7 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -10,6 +10,9 @@ concurrency: group: ${{ format('docker-ci-{0}', github.head_ref && format('pr-{0}', github.event.pull_request.number) || github.sha) }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} +env: + IMAGE_NAME: auto-gpt + jobs: build: runs-on: ubuntu-latest @@ -55,3 +58,42 @@ jobs: run: .github/workflows/scripts/docker-ci-summary.sh >> $GITHUB_STEP_SUMMARY continue-on-error: true + + # # Docker setup needs fixing before this is going to work: #1843 + # test: + # runs-on: ubuntu-latest + # needs: build + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v2 + + # - id: build + # name: Build image + # uses: docker/build-push-action@v3 + # with: + # build-args: BUILD_TYPE=dev # include pytest + # load: true # save to docker images + # tags: ${{ env.IMAGE_NAME }} + # # cache layers in GitHub Actions cache to speed up builds + # cache-from: 'type=gha' + # cache-to: type=gha,mode=max + + # - id: test + # name: Run tests + # env: + # OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + # run: | + # test_output=$(docker run ${{ env.IMAGE_NAME }} --entrypoint pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1) + # test_failure=$? + + # echo "$test_output" + + # cat << $EOF >> $GITHUB_STEP_SUMMARY + # # Tests $([ $test_failure = 0 ] && echo '✅' || echo '❌') + # \`\`\` + # $test_output + # \`\`\` + # $EOF From 2685a22edb1ec13bfeb5af9655e7cbaba33094cc Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 16:37:24 +0200 Subject: [PATCH 06/15] fix & activate Docker CI test job --- .github/workflows/docker-ci.yml | 81 ++++++++++--------- .github/workflows/docker-release.yml | 1 + .../workflows/scripts/docker-ci-summary.sh | 0 .../scripts/docker-release-summary.sh | 0 Dockerfile | 21 +++-- 5 files changed, 59 insertions(+), 44 deletions(-) mode change 100644 => 100755 .github/workflows/scripts/docker-ci-summary.sh mode change 100644 => 100755 .github/workflows/scripts/docker-release-summary.sh diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 6e6c40bfd9e7..0b60645d532e 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -59,41 +59,46 @@ jobs: run: .github/workflows/scripts/docker-ci-summary.sh >> $GITHUB_STEP_SUMMARY continue-on-error: true - # # Docker setup needs fixing before this is going to work: #1843 - # test: - # runs-on: ubuntu-latest - # needs: build - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 - - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v2 - - # - id: build - # name: Build image - # uses: docker/build-push-action@v3 - # with: - # build-args: BUILD_TYPE=dev # include pytest - # load: true # save to docker images - # tags: ${{ env.IMAGE_NAME }} - # # cache layers in GitHub Actions cache to speed up builds - # cache-from: 'type=gha' - # cache-to: type=gha,mode=max - - # - id: test - # name: Run tests - # env: - # OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - # run: | - # test_output=$(docker run ${{ env.IMAGE_NAME }} --entrypoint pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1) - # test_failure=$? - - # echo "$test_output" - - # cat << $EOF >> $GITHUB_STEP_SUMMARY - # # Tests $([ $test_failure = 0 ] && echo '✅' || echo '❌') - # \`\`\` - # $test_output - # \`\`\` - # $EOF + # Docker setup needs fixing before this is going to work: #1843 + test: + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - id: build + name: Build image + uses: docker/build-push-action@v3 + with: + build-args: BUILD_TYPE=dev # include pytest + load: true # save to docker images + tags: ${{ env.IMAGE_NAME }} + # cache layers in GitHub Actions cache to speed up builds + cache-from: 'type=gha' + cache-to: type=gha,mode=max + + - id: test + name: Run tests + env: + CI: true + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + run: | + set +e + test_output=$( + docker run --entrypoint python ${{ env.IMAGE_NAME }} -m \ + pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1 + ) + test_failure=$? + + echo "$test_output" + + cat << $EOF >> $GITHUB_STEP_SUMMARY + # Tests $([ $test_failure = 0 ] && echo '✅' || echo '❌') + \`\`\` + $test_output + \`\`\` + $EOF diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 7c52ebc60360..b8f5eb2786ed 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -41,6 +41,7 @@ jobs: name: Build image uses: docker/build-push-action@v3 with: + build-args: BUILD_TYPE=release load: true # save to docker images # push: true # TODO: uncomment when this issue is fixed: https://github.com/moby/buildkit/issues/1555 tags: > diff --git a/.github/workflows/scripts/docker-ci-summary.sh b/.github/workflows/scripts/docker-ci-summary.sh old mode 100644 new mode 100755 diff --git a/.github/workflows/scripts/docker-release-summary.sh b/.github/workflows/scripts/docker-release-summary.sh old mode 100644 new mode 100755 diff --git a/Dockerfile b/Dockerfile index 05ec1a429863..0a7f1dd0d687 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ -# Use an official Python base image from the Docker Hub -FROM python:3.10-slim - # 'dev' or 'release' container build ARG BUILD_TYPE=dev +# Use an official Python base image from the Docker Hub +FROM python:3.10-slim AS autogpt-base + # Install browsers RUN apt-get update && apt-get install -y \ chromium-driver firefox-esr \ @@ -22,12 +22,21 @@ ENV PATH="$PATH:/root/.local/bin" COPY requirements.txt . # Only install dev dependencies in dev container builds -RUN [ '${BUILD_TYPE}' = 'dev' ] || sed -i '/Items below this point will not be included in the Docker Image/,$d' requirements.txt && \ +ARG BUILD_TYPE +RUN [ "${BUILD_TYPE}" = 'dev' ] || sed -i '/Items below this point will not be included in the Docker Image/,$d' requirements.txt && \ pip install --no-cache-dir -r requirements.txt -# Copy the application files WORKDIR /app -COPY autogpt/ ./autogpt # Set the entrypoint ENTRYPOINT ["python", "-m", "autogpt"] + +# dev build -> include everything +FROM autogpt-base as autogpt-dev +ONBUILD COPY . ./ + +# release build -> include bare minimum +FROM autogpt-base as autogpt-release +ONBUILD COPY autogpt/ ./autogpt + +FROM autogpt-${BUILD_TYPE} AS auto-gpt From 0e5e4d1ccabead708c9626f8e4a289fbc7a49de0 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 16:58:41 +0200 Subject: [PATCH 07/15] add debug step to docker CI --- .github/workflows/docker-ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 0b60645d532e..dad4aba189f6 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -23,6 +23,11 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + - if: runner.debug + run: | + ls -al + du -hs * + - id: build name: Build image uses: docker/build-push-action@v3 From a223c2d5762f1f1a77419f949339a7b44327031e Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 17:02:05 +0200 Subject: [PATCH 08/15] fix Docker CI test container env --- .github/workflows/docker-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index dad4aba189f6..0191608d7070 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -94,7 +94,7 @@ jobs: run: | set +e test_output=$( - docker run --entrypoint python ${{ env.IMAGE_NAME }} -m \ + docker run --env CI --env OPENAI_API_KEY --entrypoint python ${{ env.IMAGE_NAME }} -m \ pytest --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1 ) test_failure=$? From ba9e506c24d0c6582ec54aae050779dd12d4698d Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 17:09:21 +0200 Subject: [PATCH 09/15] Docker CI build matrix --- .github/workflows/docker-ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 0191608d7070..0c3bcbb93445 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -16,6 +16,9 @@ env: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + build-type: [release, dev] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -32,6 +35,8 @@ jobs: name: Build image uses: docker/build-push-action@v3 with: + build-args: BUILD_TYPE=${{ matrix.build-type }} + tags: ${{ env.IMAGE_NAME }} load: true # save to docker images # cache layers in GitHub Actions cache to speed up builds cache-from: 'type=gha' @@ -80,8 +85,8 @@ jobs: uses: docker/build-push-action@v3 with: build-args: BUILD_TYPE=dev # include pytest - load: true # save to docker images tags: ${{ env.IMAGE_NAME }} + load: true # save to docker images # cache layers in GitHub Actions cache to speed up builds cache-from: 'type=gha' cache-to: type=gha,mode=max From 30da9cf115117748af897b2c23a16d7fa4a1811f Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 17:33:59 +0200 Subject: [PATCH 10/15] fixup build summaries --- .github/workflows/docker-ci.yml | 3 +-- .github/workflows/scripts/docker-ci-summary.sh | 2 ++ .github/workflows/scripts/docker-release-summary.sh | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 0c3bcbb93445..2335fd5995e2 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -55,10 +55,9 @@ jobs: current_ref: ${{ github.ref_name }} commit_hash: ${{ github.event.after }} - source_url: ${{ github.event.head_commit.url }} + source_url: ${{ format('{0}/tree/{1}', github.event.repository.url, github.event.release && github.event.release.tag_name || github.sha) }} push_forced_label: ${{ github.event.forced && '☢️ forced' || '' }} - head_compare_url: ${{ github.event.compare }} new_commits_json: ${{ toJSON(github.event.commits) }} compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} diff --git a/.github/workflows/scripts/docker-ci-summary.sh b/.github/workflows/scripts/docker-ci-summary.sh index fbed1975213c..dfbd7999deab 100755 --- a/.github/workflows/scripts/docker-ci-summary.sh +++ b/.github/workflows/scripts/docker-ci-summary.sh @@ -1,5 +1,6 @@ #!/bin/bash meta=$(docker image inspect "$IMAGE_NAME" | jq '.[0]') +head_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$current_ref/" <<< $compare_url_template) ref_compare_url=$(sed "s/{base}/$base_branch/; s/{head}/$commit_hash/" <<< $compare_url_template) EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) @@ -26,6 +27,7 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | cut -f-3 `# yeet Comment column`\ | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | sed 's/\$/\\$/' `# escape variable and shell expansions`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) diff --git a/.github/workflows/scripts/docker-release-summary.sh b/.github/workflows/scripts/docker-release-summary.sh index 52f56228d42b..524745fb419b 100755 --- a/.github/workflows/scripts/docker-release-summary.sh +++ b/.github/workflows/scripts/docker-release-summary.sh @@ -25,6 +25,7 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | cut -f-3 `# yeet Comment column`\ | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ + | sed 's/\$/\\$/' `# escape variable and shell expansions`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) @@ -54,7 +55,7 @@ $meta ## Build details -**Build trigger:** $event_name \`$event_ref\` +**Build trigger:** $event_name \`$current_ref\` | Parameter | Value | | -------------- | ------------ | From 4a132831b14209158e7dfba18c8c2eb4c001d941 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 17:45:13 +0200 Subject: [PATCH 11/15] fix pipes in summary --- .github/workflows/docker-ci.yml | 2 ++ .github/workflows/scripts/docker-ci-summary.sh | 3 +++ .github/workflows/scripts/docker-release-summary.sh | 1 + 3 files changed, 6 insertions(+) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 2335fd5995e2..7a7d0e7c8701 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -48,6 +48,8 @@ jobs: event_ref: ${{ github.event.ref }} event_ref_type: ${{ github.event.ref}} + build_type: ${{ matrix.build-type }} + prod_branch: stable dev_branch: master repository: ${{ github.repository }} diff --git a/.github/workflows/scripts/docker-ci-summary.sh b/.github/workflows/scripts/docker-ci-summary.sh index dfbd7999deab..ea7ff66496c8 100755 --- a/.github/workflows/scripts/docker-ci-summary.sh +++ b/.github/workflows/scripts/docker-ci-summary.sh @@ -10,6 +10,8 @@ cat << $EOF **Source:** branch \`$current_ref\` -> [$repository@\`${commit_hash:0:7}\`]($source_url) +**Build type:** \`$build_type\` + **Image size:** $((`jq -r .Size <<< $meta` / 10**6))MB ## Image details @@ -28,6 +30,7 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ | sed 's/\$/\\$/' `# escape variable and shell expansions`\ + | sed 's/|/\\|/' `# escape pipes so they don't interfere with column separators`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) diff --git a/.github/workflows/scripts/docker-release-summary.sh b/.github/workflows/scripts/docker-release-summary.sh index 524745fb419b..56e0a90221cd 100755 --- a/.github/workflows/scripts/docker-release-summary.sh +++ b/.github/workflows/scripts/docker-release-summary.sh @@ -26,6 +26,7 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ | sed 's/\$/\\$/' `# escape variable and shell expansions`\ + | sed 's/|/\\|/' `# escape pipes so they don't interfere with column separators`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) From b287b309507e67f326de6c03a41717eb7b83593d Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 17:53:00 +0200 Subject: [PATCH 12/15] optimize Dockerfile for layer caching --- Dockerfile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0a7f1dd0d687..6023cefac6ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,22 +21,20 @@ ENV PIP_NO_CACHE_DIR=yes \ ENV PATH="$PATH:/root/.local/bin" COPY requirements.txt . -# Only install dev dependencies in dev container builds -ARG BUILD_TYPE -RUN [ "${BUILD_TYPE}" = 'dev' ] || sed -i '/Items below this point will not be included in the Docker Image/,$d' requirements.txt && \ - pip install --no-cache-dir -r requirements.txt - -WORKDIR /app - # Set the entrypoint ENTRYPOINT ["python", "-m", "autogpt"] # dev build -> include everything FROM autogpt-base as autogpt-dev +RUN pip install --no-cache-dir -r requirements.txt +WORKDIR /app ONBUILD COPY . ./ # release build -> include bare minimum FROM autogpt-base as autogpt-release +RUN sed -i '/Items below this point will not be included in the Docker Image/,$d' requirements.txt && \ + pip install --no-cache-dir -r requirements.txt +WORKDIR /app ONBUILD COPY autogpt/ ./autogpt FROM autogpt-${BUILD_TYPE} AS auto-gpt From af0b15da19ed719ab10383aecdf7928ebf0fa953 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 18:15:37 +0200 Subject: [PATCH 13/15] more markdown escaping --- .github/workflows/scripts/docker-ci-summary.sh | 4 ++-- .github/workflows/scripts/docker-release-summary.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scripts/docker-ci-summary.sh b/.github/workflows/scripts/docker-ci-summary.sh index ea7ff66496c8..0a55293f7178 100755 --- a/.github/workflows/scripts/docker-ci-summary.sh +++ b/.github/workflows/scripts/docker-ci-summary.sh @@ -29,8 +29,8 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | cut -f-3 `# yeet Comment column`\ | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ - | sed 's/\$/\\$/' `# escape variable and shell expansions`\ - | sed 's/|/\\|/' `# escape pipes so they don't interfere with column separators`\ + | sed 's/\$/\\$/g' `# escape variable and shell expansions`\ + | sed 's/|/\\|/g' `# escape pipes so they don't interfere with column separators`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) diff --git a/.github/workflows/scripts/docker-release-summary.sh b/.github/workflows/scripts/docker-release-summary.sh index 56e0a90221cd..1e00f41d4563 100755 --- a/.github/workflows/scripts/docker-release-summary.sh +++ b/.github/workflows/scripts/docker-release-summary.sh @@ -25,8 +25,8 @@ $(docker history --no-trunc --format "{{.CreatedSince}}\t{{.Size}}\t\`{{.Created | cut -f-3 `# yeet Comment column`\ | sed 's/ ago//' `# fix Layer age`\ | sed 's/ # buildkit//' `# remove buildkit comment from instructions`\ - | sed 's/\$/\\$/' `# escape variable and shell expansions`\ - | sed 's/|/\\|/' `# escape pipes so they don't interfere with column separators`\ + | sed 's/\$/\\$/g' `# escape variable and shell expansions`\ + | sed 's/|/\\|/g' `# escape pipes so they don't interfere with column separators`\ | column -t -s$'\t' -o' | ' `# align columns and add separator`\ | sed 's/^/| /; s/$/ |/' `# add table row start and end pipes`) From 29b52176ed44821acabf0cca875ac574f2811a62 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 18:28:35 +0200 Subject: [PATCH 14/15] add gha cache scopes --- .github/workflows/docker-ci.yml | 8 ++++---- .github/workflows/docker-release.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 7a7d0e7c8701..c933202f16db 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -39,8 +39,8 @@ jobs: tags: ${{ env.IMAGE_NAME }} load: true # save to docker images # cache layers in GitHub Actions cache to speed up builds - cache-from: 'type=gha' - cache-to: type=gha,mode=max + cache-from: type=gha,scope=docker-${{ matrix.build-type }} + cache-to: type=gha,scope=docker-${{ matrix.build-type }},mode=max - name: Generate build report env: @@ -89,8 +89,8 @@ jobs: tags: ${{ env.IMAGE_NAME }} load: true # save to docker images # cache layers in GitHub Actions cache to speed up builds - cache-from: 'type=gha' - cache-to: type=gha,mode=max + cache-from: type=gha,scope=docker-dev + cache-to: type=gha,scope=docker-dev,mode=max - id: test name: Run tests diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index b8f5eb2786ed..e066641f04fb 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -50,8 +50,8 @@ jobs: ${{ env.DEPLOY_IMAGE_NAME }}:${{ steps.sanitize_tag.outputs.tag }} # cache layers in GitHub Actions cache to speed up builds - cache-from: ${{ !inputs.no_cache && 'type=gha' || '' }} - cache-to: type=gha,mode=max + cache-from: ${{ !inputs.no_cache && 'type=gha' || '' }},scope=docker-release + cache-to: type=gha,scope=docker-release,mode=max - name: Push image to Docker Hub run: docker push --all-tags ${{ env.DEPLOY_IMAGE_NAME }} From b84a574386a9f6869657055069cb115b9b229128 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Mon, 24 Apr 2023 18:49:33 +0200 Subject: [PATCH 15/15] add Docker CI cache clean workflow --- .github/workflows/docker-cache-clean.yml | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/docker-cache-clean.yml diff --git a/.github/workflows/docker-cache-clean.yml b/.github/workflows/docker-cache-clean.yml new file mode 100644 index 000000000000..f3fc8c10b4e8 --- /dev/null +++ b/.github/workflows/docker-cache-clean.yml @@ -0,0 +1,58 @@ +name: Purge Docker CI cache + +on: + schedule: + - cron: 20 4 * * 1,4 + +env: + BASE_BRANCH: master + IMAGE_NAME: auto-gpt + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + build-type: [release, dev] + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - id: build + name: Build image + uses: docker/build-push-action@v3 + with: + build-args: BUILD_TYPE=${{ matrix.build-type }} + load: true # save to docker images + # use GHA cache as read-only + cache-to: type=gha,scope=docker-${{ matrix.build-type }},mode=max + + - name: Generate build report + env: + event_name: ${{ github.event_name }} + event_ref: ${{ github.event.schedule }} + + build_type: ${{ matrix.build-type }} + + prod_branch: stable + dev_branch: master + repository: ${{ github.repository }} + base_branch: ${{ github.ref_name != 'master' && github.ref_name != 'stable' && 'master' || 'stable' }} + + current_ref: ${{ github.ref_name }} + commit_hash: ${{ github.sha }} + source_url: ${{ format('{0}/tree/{1}', github.event.repository.url, github.sha) }} + push_forced_label: + + new_commits_json: ${{ null }} + compare_url_template: ${{ format('/{0}/compare/{{base}}...{{head}}', github.repository) }} + + github_context_json: ${{ toJSON(github) }} + job_env_json: ${{ toJSON(env) }} + vars_json: ${{ toJSON(vars) }} + + run: .github/workflows/scripts/docker-ci-summary.sh >> $GITHUB_STEP_SUMMARY + continue-on-error: true