Skip to content

Commit

Permalink
Fix PR from forked branch (#103)
Browse files Browse the repository at this point in the history
* refactor workflows to fix pr from forked repo

* add condition to run step

* fix the condition

* set load true

* set docker buildkit to 0

* add platform

* no cache false

* no cache true

* set cache from to

* push false

* move cache

* comment start and stop runner

* fix indentation

* push to local repository

* remove local push

* fix runner label

* remove cache

* no cache true

* add platform

* uncomment lines and add x86 workflow

* rename workflow file

* do not start and stop runner from forked repo
  • Loading branch information
benlee0423 authored Feb 14, 2024
1 parent 15025e8 commit bcc9dcf
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 51 deletions.
10 changes: 9 additions & 1 deletion .github/action_templates/build-and-push/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
dockerfile-name:
description: 'The name of dockerfile to use'
required: true
platform:
description: 'The platform to build'
required: false

runs:
using: "composite"
Expand All @@ -29,6 +32,12 @@ runs:
echo "TAG_NAME=${GITHUB_REF##*/}" >> "$GITHUB_ENV"
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}

- name: Attach platform to tag
shell: bash
run: |
echo "TAG_NAME=${{env.TAG_NAME}}-${{inputs.platform}}" >> "$GITHUB_ENV"
if: "${{ inputs.platform != 'ARM64' }}"

- name: Login to Docker Hub
shell: bash
run: |
Expand All @@ -47,7 +56,6 @@ runs:
build-args: |
TAG_NAME=${{ env.TAG_NAME}}
push: true
platforms: linux/arm64
tags: |
awiciroh/${{ inputs.image-name}}:${{ env.TAG_NAME}}
builder: mybuilder
Expand Down
58 changes: 58 additions & 0 deletions .github/action_templates/build-and-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: build and test template
description: "A template to build and test docker image based on provided inputs"

inputs:
docker-auth-token:
description: 'Docker Hub authentication token'
required: true
image-name:
description: 'image name to be built'
required: true
dockerfile-name:
description: 'The name of dockerfile to use'
required: true
platform:
description: 'The platform to build'
required: false

runs:
using: "composite"
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Set env vars for main branch
shell: bash
run: |
echo "TAG_NAME=latest" >> "$GITHUB_ENV"
if: startsWith(github.ref, 'refs/heads/main')
- name: Set env vars for other branch
shell: bash
run: |
echo "TAG_NAME=${GITHUB_REF##*/}" >> "$GITHUB_ENV"
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Attach platform to tag
shell: bash
run: |
echo "TAG_NAME=${{env.TAG_NAME}}-${{inputs.platform}}" >> "$GITHUB_ENV"
if: "${{ inputs.platform != 'ARM64' }}"
- name: Create Cache and Builder for Buildx
shell: bash
run: |
docker buildx create --use --name mybuilder --node mybuilder
- name: Build and Cache Docker Image
uses: docker/build-push-action@v5
with:
context: ./docker
file: ./docker/${{ inputs.dockerfile-name}}
build-args: |
TAG_NAME=${{ env.TAG_NAME}}
push: true
tags: |
awiciroh/${{ inputs.image-name}}:${{ env.TAG_NAME}}
builder: mybuilder
no-cache: true
env:
DOCKER_BUILDKIT: 1
DOCKER_CLI_EXPERIMENTAL: enabled
25 changes: 16 additions & 9 deletions .github/workflows/docker_deps_image.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
name: Build and push deps image
on:
push:
branches: [ main ]
paths:
- docker/**
workflow_dispatch:
workflow_call:
inputs:
runner_label:
required: true
type: string
jobs:
build-and-push:
runs-on: self-hosted
strategy:
matrix:
architecture: [arm64]
runs-on: ["${{inputs.runner_label}}"]
steps:
- name: deploy
uses: actions/checkout@v2
- name: Build and test Docker image
uses: ./.github/action_templates/build-and-test
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ngen-deps"
dockerfile-name: "Dockerfile.ngen-deps"
platform: ${{inputs.runner_label}}
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Build and push Docker image
uses: ./.github/action_templates/build-and-push
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ngen-deps"
dockerfile-name: "Dockerfile.ngen-deps"
dockerfile-name: "Dockerfile.ngen-deps"
platform: ${{inputs.runner_label}}
if: startsWith(github.ref, 'refs/heads/main')
71 changes: 44 additions & 27 deletions .github/workflows/docker_image_main_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,79 @@ name: Build and push final image
on:
push:
branches: [ main ]
paths:
- docker/**
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
start-runner:
runs-on: ubuntu-latest
steps:
- name: start runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StartCirohRunner
runs-on: ubuntu-latest
steps:
- name: start runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StartCirohRunner
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA')

- name: wait runner up
shell: bash
run: |
sleep 300
- name: wait runner up
shell: bash
run: |
sleep 300
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA')
deps:
needs: start-runner
uses: ./.github/workflows/docker_deps_image.yml
with:
runner_label: ARM64
secrets: inherit
troute:
needs: deps
uses: ./.github/workflows/docker_troute_image.yml
with:
runner_label: ARM64
secrets: inherit
ngen:
needs: troute
uses: ./.github/workflows/docker_ngen_image.yml
with:
runner_label: ARM64
secrets: inherit
final:
needs: ngen
runs-on: self-hosted
runs-on: ARM64
steps:
- name: deploy
uses: actions/checkout@v2
- name: Build and test Docker image
uses: ./.github/action_templates/build-and-test
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: ARM64
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Build and push Docker image
uses: ./.github/action_templates/build-and-push
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: ARM64
if: startsWith(github.ref, 'refs/heads/main')
check_result:
needs: final
runs-on: self-hosted
runs-on: ARM64
outputs:
output1: ${{ steps.step1.outputs.result }}
steps:
- id: step1
run: echo "result=success" >> "$GITHUB_OUTPUT"

slack:
runs-on: self-hosted
if: ${{ always() }}
runs-on: ARM64
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA')
needs: [deps, troute, ngen, final, check_result]
env:
OUTPUT: ${{needs.check_result.outputs.output1}}
Expand All @@ -84,12 +100,13 @@ jobs:
pull_request_url: ${{ github.event.pull_request.html_url }}
head_commit_url: ${{ github.event.head_commit.url }}
stop-runner:
needs: slack
runs-on: ubuntu-latest
steps:
- name: stop runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StopCirohRunner
needs: slack
runs-on: ubuntu-latest
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA')
steps:
- name: stop runner
uses: gagoar/invoke-aws-lambda@master
with:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
FunctionName: StopCirohRunner
80 changes: 80 additions & 0 deletions .github/workflows/docker_image_main_x86.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: X86 Build and push final image
on:
workflow_dispatch:

jobs:
deps:
uses: ./.github/workflows/docker_deps_image.yml
with:
runner_label: X86
secrets: inherit
troute:
needs: deps
uses: ./.github/workflows/docker_troute_image.yml
with:
runner_label: X86
secrets: inherit
ngen:
needs: troute
uses: ./.github/workflows/docker_ngen_image.yml
with:
runner_label: X86
secrets: inherit
final:
needs: ngen
runs-on: X86
steps:
- name: deploy
uses: actions/checkout@v2
- name: Build and test Docker image
uses: ./.github/action_templates/build-and-test
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: X86
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Build and push Docker image
uses: ./.github/action_templates/build-and-push
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ciroh-ngen-image"
dockerfile-name: "Dockerfile"
platform: X86
if: startsWith(github.ref, 'refs/heads/main')
check_result:
needs: final
runs-on: X86
outputs:
output1: ${{ steps.step1.outputs.result }}
steps:
- id: step1
run: echo "result=success" >> "$GITHUB_OUTPUT"

slack:
runs-on: X86
if: ${{ always() }}
needs: [deps, troute, ngen, final, check_result]
env:
OUTPUT: ${{needs.check_result.outputs.output1}}
steps:
- name: Set env JOBSTATUS
run: |
echo "$OUTPUT"
if [[ "success" = "$OUTPUT" ]]
then
echo "JOBSTATUS=success" >> "$GITHUB_ENV"
else
echo "JOBSTATUS=failure" >> "$GITHUB_ENV"
fi
- run: echo "$JOBSTATUS"
- name: deploy
uses: actions/checkout@v2
- name: Publish slack message
if: always()
uses: ./.github/action_templates/slack
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
job-status: ${{ env.JOBSTATUS }}
pull_request_url: ${{ github.event.pull_request.html_url }}
head_commit_url: ${{ github.event.head_commit.url }}
23 changes: 16 additions & 7 deletions .github/workflows/docker_ngen_image.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
name: Build and push ngen image
on:
push:
branches: [ main ]
paths:
- docker/**
workflow_dispatch:
workflow_call:

inputs:
runner_label:
required: true
type: string
jobs:
build-and-push:
runs-on: self-hosted
runs-on: ["${{inputs.runner_label}}"]
steps:
- name: deploy
uses: actions/checkout@v2
- name: Build and push Docker image
uses: ./.github/action_templates/build-and-test
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ngen"
dockerfile-name: "Dockerfile.ngen"
platform: ${{inputs.runner_label}}
if: ${{ !startsWith(github.ref, 'refs/heads/main') }}
- name: Build and push Docker image
uses: ./.github/action_templates/build-and-push
with:
docker-auth-token: ${{ secrets.DOCKER_AUTH_TOKEN }}
image-name: "ngen"
dockerfile-name: "Dockerfile.ngen"
dockerfile-name: "Dockerfile.ngen"
platform: ${{inputs.runner_label}}
if: startsWith(github.ref, 'refs/heads/main')
Loading

0 comments on commit bcc9dcf

Please sign in to comment.