Skip to content

docker

docker #4340

Workflow file for this run

name: docker
on:
schedule:
- cron: "0 10 * * *" # everyday at 10am
push:
branches: ["master", "release-*"]
tags: ["v*.*.*"]
jobs:
start-runner:
name: Start self-hosted EC2 runner
if: >
github.event_name == 'schedule' && github.repository == 'ludwig-ai/ludwig' ||
github.event_name == 'push' && github.repository == 'ludwig-ai/ludwig' ||
github.event_name == 'pull_request' && github.event.pull_request.base.repo.full_name == 'ludwig-ai/ludwig' && !github.event.pull_request.head.repo.fork
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_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Start EC2 runner
id: start-ec2-runner
uses: machulav/[email protected]
with:
mode: start
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
ec2-image-id: ami-0759580dedc953d1f
ec2-instance-type: r5.large
subnet-id: subnet-0983be43
security-group-id: sg-4cba0d08
aws-resource-tags: >
[
{"Key": "Name", "Value": "ludwig-github-${{ github.head_ref || github.sha }}"},
{"Key": "GitHubRepository", "Value": "${{ github.repository }}"},
{"Key": "GitHubHeadRef", "Value": "${{ github.head_ref }}"},
{"Key": "GitHubSHA", "Value": "${{ github.sha }}"}
]
docker:
name: Build docker image ${{ matrix.docker-image }} (push=${{ github.event_name != 'pull_request' }})
if: needs.start-runner.result != 'skipped'
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 runners
# we want an ongoing run of this workflow to be canceled by a later commit
# so that there is only one concurrent run of this workflow for each branch
concurrency:
group: docker-${{ matrix.docker-image }}-${{ github.head_ref || github.sha }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix:
docker-image:
- ludwig
- ludwig-gpu
- ludwig-ray
- ludwig-ray-gpu
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: crazy-max/ghaction-docker-meta@v2
with:
# list of Docker images to use as base name for tags
images: |
ludwigai/${{ matrix.docker-image }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/${{ matrix.docker-image }}/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
stop-runner:
name: Stop self-hosted EC2 runner
# required to stop the runner even if the error happened in the previous job
if: always() && needs.start-runner.result != 'skipped'
needs:
- start-runner # required to get output from the start-runner job
- docker # required to wait when the main job is done
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Stop EC2 runner
uses: machulav/[email protected]
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 }}