Skip to content

add trigger osd-build-image #2

add trigger osd-build-image

add trigger osd-build-image #2

name: Build-OSD-Image
on:
push:
branches: [ ec2-runner ]
workflow_dispatch:
inputs:
python_version:
description: Python version
type: string
default: '3.9.17'
required: true
node_version:
description: Node version
type: string
default: '18.19.0'
required: true
openSearch-dashboards_version:
description: OpenSearch-Dashboards version
type: string
default: '3.0.0'
required: true
additional_args:
description: JSON of additional options
type: string
default: '{}'
required: true
build_number:
description: Build number
type: string
default: ''
required: false
jobs:
start-runner:
name: Start self-hosted EC2 runner
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-ec2-runner.outputs.label }}
ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }}
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RUNNER }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RUNNER }}
aws-region: ${{ secrets.AWS_REGION_RUNNER }}
- name: Start EC2 runner
id: start-ec2-runner
uses: elastic-analytics/ec2-github-runner@runner-as-a-service
with:
mode: start
github-token: ${{ secrets.GH_ACCESS_TOKEN_RUNNER }}
ec2-image-id: ${{ secrets.EC2_IMAGE_ID_RUNNER }}
ec2-instance-type: ${{ secrets.EC2_INSTANCE_TYPE_RUNNER }}
subnet-id: ${{ secrets.SUBNET_ID_RUNNER }}
security-group-id: ${{ secrets.SECURITY_GROUP_ID_RUNNER }}
iam-role-name: action-ec2-role
aws-resource-tags: >
[
{"Key": "Name", "Value": "ec2-github-runner"},
{"Key": "GitHubRepository", "Value": "${{ github.repository }}"}
]
run-runner-as-service: true
run-runner-as-user: ${ secrets.RUN_RUNNER_AS_USER }
build-osd-image-job:
name: Build Opensearch-Dashboards Image
needs: start-runner # required to start the main job when the runner is ready.
runs-on: ${{ needs.start-runner.outputs.label }} # run the job on the newly created runner
env:
PYTHON_VERSION: ${{ github.event.inputs.python_version }}
NODE_VERSION: ${{ github.event.inputs.node_version }}
OSD_VERSION: ${{ github.event.inputs.openSearch-dashboards_version }}
steps:
- name: Start To Build Opensearch-Dashboards Image
run: echo 'Start To Build Opensearch-Dashboards Image!'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RUNNER }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RUNNER }}
aws-region: ${{ secrets.AWS_REGION_RUNNER }}
- name: Checkout opensearch-build repo
uses: actions/checkout@v3
with:
repository: opensearch-project/opensearch-build
path: opensearch-build
ref: action
- name: Replace fork for build
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/opensearch-build/manifests/${{ env.OSD_VERSION}}/opensearch-dashboards-${{ env.OSD_VERSION}}.yml"]'
tokenPrefix: '${'
tokenSuffix: '}'
env:
OpenSearch-Dashboards_ref: ${{ fromJson(inputs.additional_args).OpenSearch-Dashboards_ref }}
OpenSearch-Dashboards_repository: ${{ fromJson(inputs.additional_args).OpenSearch-Dashboards_repository }}
functionalTestDashboards_ref: ${{ fromJson(inputs.additional_args).functionalTestDashboards_ref }}
functionalTestDashboards_repository: ${{ fromJson(inputs.additional_args).functionalTestDashboards_repository }}
reportsDashboards_ref: ${{ fromJson(inputs.additional_args).reportsDashboards_ref }}
reportsDashboards_repository: ${{ fromJson(inputs.additional_args).reportsDashboards_repository }}
securityDashboards_ref: ${{ fromJson(inputs.additional_args).securityDashboards_ref }}
securityDashboards_repository: ${{ fromJson(inputs.additional_args).securityDashboards_repository }}
queryWorkbenchDashboards_ref: ${{ fromJson(inputs.additional_args).queryWorkbenchDashboards_ref }}
queryWorkbenchDashboards_repository: ${{ fromJson(inputs.additional_args).queryWorkbenchDashboards_repository }}
searchRelevanceDashboards_ref: ${{ fromJson(inputs.additional_args).searchRelevanceDashboards_ref }}
searchRelevanceDashboards_repository: ${{ fromJson(inputs.additional_args).searchRelevanceDashboards_repository }}
observabilityDashboards_ref: ${{ fromJson(inputs.additional_args).observabilityDashboards_ref }}
observabilityDashboards_repository: ${{ fromJson(inputs.additional_args).observabilityDashboards_repository }}
ganttChartDashboards_ref: ${{ fromJson(inputs.additional_args).ganttChartDashboards_ref }}
ganttChartDashboards_repository: ${{ fromJson(inputs.additional_args).ganttChartDashboards_repository }}
assistantDashboards_ref: ${{ fromJson(inputs.additional_args).assistantDashboards_ref }}
assistantDashboards_repository: ${{ fromJson(inputs.additional_args).assistantDashboards_repository }}
notificationsDashboards_ref: ${{ fromJson(inputs.additional_args).notificationsDashboards_ref }}
notificationsDashboards_repository: ${{ fromJson(inputs.additional_args).notificationsDashboards_repository }}
customImportMapDashboards_ref: ${{ fromJson(inputs.additional_args).customImportMapDashboards_ref }}
customImportMapDashboards_repository: ${{ fromJson(inputs.additional_args).customImportMapDashboards_repository }}
anomalyDetectionDashboards_ref: ${{ fromJson(inputs.additional_args).anomalyDetectionDashboards_ref }}
anomalyDetectionDashboards_repository: ${{ fromJson(inputs.additional_args).anomalyDetectionDashboards_repository }}
mlCommonsDashboards_ref: ${{ fromJson(inputs.additional_args).mlCommonsDashboards_ref }}
mlCommonsDashboards_repository: ${{ fromJson(inputs.additional_args).mlCommonsDashboards_repository }}
indexManagementDashboards_ref: ${{ fromJson(inputs.additional_args).indexManagementDashboards_ref }}
indexManagementDashboards_repository: ${{ fromJson(inputs.additional_args).indexManagementDashboards_repository }}
alertingDashboards_ref: ${{ fromJson(inputs.additional_args).alertingDashboards_ref }}
alertingDashboards_repository: ${{ fromJson(inputs.additional_args).alertingDashboards_repository }}
securityAnalyticsDashboards_ref: ${{ fromJson(inputs.additional_args).securityAnalyticsDashboards_ref }}
securityAnalyticsDashboards_repository: ${{ fromJson(inputs.additional_args).securityAnalyticsDashboards_repository }}
- name: Build and assemble
run: |
cd opensearch-build
echo "BUILD_NUMBER=${{ github.event.inputs.build_number || github.run_id }}"
export BUILD_NUMBER=${{ github.event.inputs.build_number || github.run_id }}
echo "opensearch-dashboards-${{ env.OSD_VERSION }} manifest"
cat manifests/${{ env.OSD_VERSION }}/opensearch-dashboards-${{ env.OSD_VERSION }}.yml
source ~/.bash_profile
./build.sh manifests/${{ env.OSD_VERSION}}/opensearch-dashboards-${{ env.OSD_VERSION}}.yml -d tar -p linux -a x64
./assemble.sh tar/builds/opensearch-dashboards/manifest.yml
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Build and push docker image
env:
REGISTRY: ${{ steps.login-ecr-public.outputs.registry }}
REGISTRY_ALIAS: ${{ steps.REGISTRY_ALIAS_RUNNER }}
REPOSITORY: 'actionrunner'
IMAGE_TAG: ${{ env.OSD_VERSION}}-${{ github.run_id }}
run: |
artifact_name=opensearch-dashboards-${{ env.OSD_VERSION}}-linux-x64.tar.gz
tarball=$(realpath opensearch-build/tar/dist/opensearch-dashboards/$artifact_name)
cd ./opensearch-build/docker/release
./build-image-single-arch.sh -v $IMAGE_TAG -p opensearch-dashboards -a x64 -f ./dockerfiles/opensearch-dashboards.al2023.dockerfile -t $tarball
docker images
docker tag opensearchproject/opensearch-dashboards:$IMAGE_TAG $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
echo "Pushed docker image: $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG"
stop-runner:
name: Stop self-hosted EC2 runner
needs:
- start-runner # required to get output from the start-runner job
- build-osd-image-job # required to wait when the main job is done
runs-on: ubuntu-latest
if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_RUNNER }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_RUNNER }}
aws-region: ${{ secrets.AWS_REGION_RUNNER }}
- name: Stop EC2 runner
uses: elastic-analytics/ec2-github-runner@runner-as-a-service
with:
mode: stop
github-token: ${{ secrets.GH_ACCESS_TOKEN_RUNNER }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}