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

Speed Up Publish OSS Artifacts for Cloud Workflow #19696

Merged
merged 14 commits into from
Dec 14, 2022
38 changes: 12 additions & 26 deletions .github/actions/build-branch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ inputs:
branch_version_tag:
description: 'Used to tag jars and docker images with a branch-specific version (should use the form "dev-<commit_hash>" to pass AirbyteVersion validation)'
required: false
build_docker_images:
description: 'Build docker images'
default: 'true'
required: false
outputs:
branch_version_tag:
description: "Tag used for jars and docker images. Either user specified or auto generated as `dev-<commit_hash>`"
Expand All @@ -20,35 +24,17 @@ runs:
[[ "${{ inputs.branch_version_tag }}" != '' ]] && echo "branch_version_tag=${{ inputs.branch_version_tag }}" >> $GITHUB_OUTPUT \
|| { short_hash=$(git rev-parse --short=10 HEAD); echo "branch_version_tag=dev-$short_hash" >> $GITHUB_OUTPUT ; }

- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"

- uses: actions/setup-node@v3
with:
node-version: "lts/gallium"

- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Prepare Runner for Building
uses: ./.github/actions/runner-prepare-for-build

- name: Set up CI Gradle Properties
run: |
mkdir -p ~/.gradle/
cat > ~/.gradle/gradle.properties <<EOF
org.gradle.jvmargs=-Xmx8g -Xss4m --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
org.gradle.workers.max=8
org.gradle.vfs.watch=false
EOF
- name: Build with Docker Images
if: inputs.build_docker_images == 'true'
run: VERSION=${{ steps.parse-input.outputs.branch_version_tag }} SUB_BUILD=PLATFORM ./gradlew build --scan
shell: bash

- name: Build
run: VERSION=${{ steps.parse-input.outputs.branch_version_tag }} SUB_BUILD=PLATFORM ./gradlew build --scan
- name: Build without Docker Images
if: inputs.build_docker_images != 'true'
run: VERSION=${{ steps.parse-input.outputs.branch_version_tag }} SUB_BUILD=PLATFORM ./gradlew test --scan
shell: bash

- name: Publish to Maven Local
Expand Down
47 changes: 47 additions & 0 deletions .github/actions/runner-prepare-for-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: 'Prepare Runner for Building'
description: 'Prepare Runner for Building project'
inputs:
install_java:
description: ''
required: false
default: 'true'
install_node:
description: ''
required: false
default: 'true'
install_python:
description: ''
required: false
default: 'true'
runs:
using: "composite"
steps:
- if: inputs.install_java == 'true'
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "17"

- if: inputs.install_node == 'true'
uses: actions/setup-node@v3
with:
node-version: "lts/gallium"

- if: inputs.install_python == 'true'
uses: actions/setup-python@v4
with:
python-version: "3.9"

- if: inputs.install_java == 'true'
name: Set up CI Gradle Properties
run: |
mkdir -p ~/.gradle/
cat > ~/.gradle/gradle.properties <<EOF
org.gradle.jvmargs=-Xmx8g -Xss4m --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
org.gradle.vfs.watch=false
EOF
shell: bash
43 changes: 41 additions & 2 deletions .github/workflows/publish-oss-for-cloud.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Publish OSS Artifacts for Cloud
concurrency:
group: ${{ github.workflow }}-${{ inputs.oss_ref || github.sha }}

env:
S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.SELF_RUNNER_AWS_ACCESS_KEY_ID }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment is nice here that says something along the lines of

//these environment variables are necessary for gradle cache task

S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.SELF_RUNNER_AWS_SECRET_ACCESS_KEY }}
davinchia marked this conversation as resolved.
Show resolved Hide resolved

on:
workflow_dispatch:
Expand All @@ -10,6 +12,9 @@ on:
required: false
jobs:
find_valid_pat:
concurrency:
Copy link
Contributor

Choose a reason for hiding this comment

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

for my understanding: what is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is so only one instance of this workflow can be actively running for a specific oss sha (so we don't attempt to push artifacts for the same sha from multiple concurrent workflows)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah ok! can we also add a comment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added comments

group: ${{ github.workflow }}-${{ inputs.oss_ref || github.sha }}
cancel-in-progress: false
name: "Find a PAT with room for actions"
timeout-minutes: 10
runs-on: ubuntu-latest
Expand Down Expand Up @@ -91,6 +96,7 @@ jobs:
uses: ./.github/actions/build-branch
with:
branch_version_tag: ${{ needs.generate-tags.outputs.dev_tag }}
build_docker_images: 'false'

- name: Publish Dev Jars
env:
Expand Down Expand Up @@ -134,6 +140,13 @@ jobs:
echo "GIT_REVISION=${GIT_REVISION}" >> $GITHUB_ENV
shell: bash

- name: Prepare Runner for Building
uses: ./.github/actions/runner-prepare-for-build

- name: Prepare Docker context
run: VERSION=${{ needs.generate-tags.outputs.dev_tag }} SUB_BUILD=PLATFORM ./gradlew copyGeneratedTar airbyte-db:db-lib:copyInitSql
davinchia marked this conversation as resolved.
Show resolved Hide resolved
shell: bash

- name: Push Docker Images
env:
VERSION: ${{ needs.generate-tags.outputs.dev_tag }}
Expand All @@ -144,3 +157,29 @@ jobs:
- name: Cleanup Docker buildx
run: docker buildx rm oss-buildx
shell: bash

stop-runner:
Copy link
Contributor

Choose a reason for hiding this comment

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

oh did we previously not stop runners?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup, seems like a bug that went unnoticed

Copy link
Contributor

Choose a reason for hiding this comment

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

yikes - good catch

name: "Stop Build EC2 Runner"
timeout-minutes: 10
needs:
- start-runner # required to get output from the start-runner job
- docker-push # wait until all publish steps are done
- find_valid_pat
runs-on: ubuntu-latest
# Always is required to stop the runner even if the previous job has errors. However always() runs even if the previous step is skipped.
# Thus, we check for skipped here.
if: ${{ always() && needs.start-runner.result != 'skipped'}}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.SELF_RUNNER_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.SELF_RUNNER_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2
- name: Stop EC2 runner
uses: airbytehq/ec2-github-runner@base64v1.1.0
with:
mode: stop
github-token: ${{ needs.find_valid_pat.outputs.pat }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}