Skip to content

Push marqo-base img to Dockerhub #30

Push marqo-base img to Dockerhub

Push marqo-base img to Dockerhub #30

name: Push marqo-base img to Dockerhub
on:
workflow_dispatch:
inputs:
marqo_base_ref:
description: 'marqo-base branch-name, commit SHA or tag'
required: true
default: 'main'
custom_docker_tag:
description: |
Optionally add the name of the image tag. For example: "test".
Leave this empty to use the GitHub run_number incrementing integer as the tag.
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@v1
with:
aws-access-key-id: ${{ secrets.AWS_EC2_GH_RUNNER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_EC2_GH_RUNNER_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Start EC2 runner
id: start-ec2-runner
uses: machulav/ec2-github-runner@fcfb31a5760dad1314a64a0e172b78ec6fc8a17e # v2.3.6
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# 200 GB amd64 image
ec2-image-id: ${{ secrets.AWS_IMG_BUILDER_AMI }}
ec2-instance-type: t3.xlarge
subnet-id: ${{ secrets.AWS_IMG_BUILDER_SUBNET_ID }}
security-group-id: ${{ secrets.AWS_IMG_BUILDER_SEC_GROUP_ID }}
Docker-Build:
name: Build docker 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
environment:
name: marqo-base-dockerhub
steps:
- name: Checkout marqo-base
uses: actions/checkout@v3
with:
repository: marqo-ai/marqo-base
ref: ${{ github.event.inputs.marqo_base_ref }}
- id: set_image_pointer
run: |
if [[ "${{ github.event.inputs.custom_docker_tag }}" != "" ]]; then
TAG=${{ github.event.inputs.custom_docker_tag }}
else
TAG=${{ github.run_number }}
fi
IMAGE_POINTER="marqoai/marqo-base:$TAG"
echo "::set-output name=image_pointer::$IMAGE_POINTER"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.set_image_pointer.outputs.image_pointer }}
- name: Save Docker image location to metadata file
run: echo "${{ steps.set_image_pointer.outputs.image_pointer }}" > img_info.txt
- name: Upload Docker image location as artifact
uses: actions/upload-artifact@v2
with:
name: docker-image-info
path: img_info.txt
Stop-Runner:
name: Stop self-hosted EC2 runner
needs:
- Start-Runner # required to get output from the start-runner job
- Docker-Build # 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@v1
with:
aws-access-key-id: ${{ secrets.AWS_EC2_GH_RUNNER_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_EC2_GH_RUNNER_SECRET_ACCESS_KEY }}
aws-region: us-west-2
- name: Stop EC2 runner
uses: machulav/ec2-github-runner@fcfb31a5760dad1314a64a0e172b78ec6fc8a17e # v2.3.6
with:
mode: stop
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}