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

fix(ci): ephemeral env build #26852

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .asf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ github:
- cypress-matrix (1, chrome)
- cypress-matrix (2, chrome)
- cypress-matrix (3, chrome)
- docker-build
- frontend-build
- pre-commit (3.9)
- python-lint (3.9)
Expand Down
39 changes: 0 additions & 39 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,3 @@ jobs:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
run: |
./scripts/docker_build_push.sh "" ${{ matrix.target }} ${{ matrix.platform }}


ephemeral-docker-build:
name: docker-build
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build ephemeral env image
if: github.event_name == 'pull_request'
run: |
mkdir -p ./build
echo ${{ github.sha }} > ./build/SHA
echo ${{ github.event.pull_request.number }} > ./build/PR-NUM
docker buildx build --target ci \
--load \
--cache-from=type=registry,ref=apache/superset:lean \
-t ${{ github.sha }} \
-t "pr-${{ github.event.pull_request.number }}" \
--platform linux/amd64 \
--label "build_actor=${GITHUB_ACTOR}" \
.
docker save ${{ github.sha }} | gzip > ./build/${{ github.sha }}.tar.gz

- name: Upload build artifacts
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: build
path: build/
73 changes: 34 additions & 39 deletions .github/workflows/ephemeral-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,55 +79,51 @@ jobs:
})
core.setFailed(errMsg)

docker_ephemeral_env:
needs: config
if: needs.config.outputs.has-secrets
name: Push ephemeral env Docker image to ECR
ephemeral-docker-build:
needs: ephemeral_env_comment
name: docker-build
runs-on: ubuntu-latest

steps:
- name: "Download artifact"
uses: actions/[email protected]
- name: Get Info from comment
uses: actions/github-script@v3
id: get-pr-info
with:
script: |
const artifacts = await github.actions.listWorkflowRunArtifacts({
const request = {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});

core.info('*** artifacts')
core.info(JSON.stringify(artifacts))

const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name === "build";
});

if (!matchArtifact.length) {
return core.setFailed("Build artifacts not found");
pull_number: ${{ github.event.issue.number }},
}
core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`)
const pr = await github.pulls.get(request);
Copy link
Member Author

Choose a reason for hiding this comment

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

To fetch the last SHA from the PR where the comment was made, more details here: actions/checkout#331

return pr.data;

const download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact[0].id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/build.zip', Buffer.from(download.data));
- name: Debug
id: get-sha
run: |
echo "sha=${{ fromJSON(steps.get-pr-info.outputs.result).head.sha }}" >> $GITHUB_OUTPUT

- run: unzip build.zip
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} : ${{steps.get-sha.outputs.sha}} )"
uses: actions/checkout@v4
with:
ref: ${{ steps.get-sha.outputs.sha }}
persist-credentials: false

- name: Display downloaded files (debug)
run: ls -la
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Get SHA
id: get-sha
run: echo "::set-output name=sha::$(cat ./SHA)"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get PR
id: get-pr
run: echo "::set-output name=num::$(cat ./PR-NUM)"
- name: Build ephemeral env image
run: |
docker buildx build --target ci \
--load \
-t ${{ steps.get-sha.outputs.sha }} \
-t "pr-${{ github.event.issue.number }}" \
--platform linux/amd64 \
--label "build_actor=${GITHUB_ACTOR}" \
.

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -146,9 +142,8 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: superset-ci
SHA: ${{ steps.get-sha.outputs.sha }}
IMAGE_TAG: pr-${{ steps.get-pr.outputs.num }}
IMAGE_TAG: pr-${{ github.event.issue.number }}
run: |
docker load < $SHA.tar.gz
docker tag $SHA $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $SHA $ECR_REGISTRY/$ECR_REPOSITORY:$SHA
docker push -a $ECR_REGISTRY/$ECR_REPOSITORY
Expand Down
Loading