Skip to content

Build and push final image #396

Build and push final image

Build and push final image #396

name: Build and push final image
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
start-runner:
runs-on: ubuntu-latest
steps:
- name: start arm 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') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
- name: start x86 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: StartCirohX86Runner
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
- name: wait runner up
shell: bash
run: |
sleep 300
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
init:
needs: start-runner
runs-on: ${{ matrix.runner}}
strategy:
matrix:
runner: [ARM64, x86]
steps:
- name: clear docker cache
run: |
docker system prune -af
build:
needs: init
runs-on: ${{ matrix.runner}}
strategy:
matrix:
runner: [arm64, 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: ${{ matrix.runner}}
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: ${{ matrix.runner}}
if: startsWith(github.ref, 'refs/heads/main')
check_result:
needs: build
runs-on: ${{ matrix.runner}}
strategy:
matrix:
runner: [ARM64, x86]
outputs:
output1: ${{ steps.step1.outputs.result }}
steps:
- id: step1
run: echo "result=success" >> "$GITHUB_OUTPUT"
create-manifest:
needs: check_result
runs-on: ARM64
steps:
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: awiciroh
password: ${{ secrets.DOCKER_AUTH_TOKEN }}
- name: Create and push manifest
run: |
docker manifest create ${{ secrets.DOCKERHUB_USERNAME }}/ciroh-ngen-image:latest \
awiciroh/ciroh-ngen-image:latest-arm64 \
awiciroh/ciroh-ngen-image:latest-x86
docker manifest push awiciroh/ciroh-ngen-image:latest
slack:
runs-on: ARM64
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
needs: [build, 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 }}
stop-runner:
needs: slack
runs-on: ubuntu-latest
if: startsWith(github.event.pull_request.head.repo.full_name, 'CIROH-UA') ||
(startsWith(github.ref, 'refs/heads/main') && github.event_name != 'pull_request')
steps:
- name: stop arm 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
- name: stop x86 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: StopCirohX86Runner