|
| 1 | +name: ML Workflow Via Actions |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [labeled] |
| 5 | + |
| 6 | +jobs: |
| 7 | + |
| 8 | + ml-workflow: |
| 9 | + if: github.actor == 'pr-chatops[bot]' |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + |
| 13 | + - name: Copy Repository Contents |
| 14 | + uses: actions/checkout@master |
| 15 | + |
| 16 | + - name: Trigger on PR Label |
| 17 | + id: label |
| 18 | + run: python action_files/validate_payload.py |
| 19 | + env: |
| 20 | + TRIGGER_LABEL_NAME: "Full Test Pending" |
| 21 | + |
| 22 | + - name: Publish CPU Image to DockerHub |
| 23 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 24 | + run: | |
| 25 | + cd $GITHUB_WORKSPACE |
| 26 | + echo ${PASSWORD} | docker login -u $USERNAME --password-stdin |
| 27 | + BASE_NAME="$USERNAME/ml-cicd" |
| 28 | + IMAGE_NAME="$BASE_NAME:$GITHUB_SHA" |
| 29 | + docker pull $BASE_NAME || true |
| 30 | + docker build --cache-from $BASE_NAME -t $IMAGE_NAME -t $BASE_NAME -f docker/Dockerfile . |
| 31 | + docker push $IMAGE_NAME |
| 32 | + docker push $BASE_NAME |
| 33 | + env: |
| 34 | + USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 35 | + PASSWORD: ${{ secrets.DOCKER_PASSWORD }} |
| 36 | + |
| 37 | + - name: Publish GPU Image to DockerHub |
| 38 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 39 | + run: | |
| 40 | + cd $GITHUB_WORKSPACE |
| 41 | + echo ${PASSWORD} | docker login -u $USERNAME --password-stdin |
| 42 | + BASE_NAME="$USERNAME/ml-cicd-gpu" |
| 43 | + IMAGE_NAME="$BASE_NAME:$GITHUB_SHA" |
| 44 | + docker pull $BASE_NAME || true |
| 45 | + docker build --cache-from $BASE_NAME -t $IMAGE_NAME -t $BASE_NAME -f docker/Dockerfile . |
| 46 | + docker push $IMAGE_NAME |
| 47 | + docker push $BASE_NAME |
| 48 | + env: |
| 49 | + USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 50 | + PASSWORD: ${{ secrets.DOCKER_PASSWORD }} |
| 51 | + |
| 52 | + - name: Build Argo Param File |
| 53 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 54 | + run: | |
| 55 | + cd $GITHUB_WORKSPACE |
| 56 | + echo "GITHUB-SHA: $SHA" >> pipelines/params.yaml |
| 57 | + echo "PR-NUMBER: $PR_NUMBER" >> pipelines/params.yaml |
| 58 | + echo "REPO: $GITHUB_REPOSITORY" >> pipelines/params.yaml |
| 59 | + env: |
| 60 | + SHA: ${{ steps.label.outputs.HEAD_SHA }} |
| 61 | + PR_NUMBER: ${{ steps.label.outputs.ISSUE_NUMBER }} |
| 62 | + |
| 63 | + - name: Submit Argo Deployment |
| 64 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 65 | + id: argo |
| 66 | + uses: machine-learning-apps/gke-argo@master |
| 67 | + with: |
| 68 | + ARGO_URL: ${{ secrets.ARGO_URI }} |
| 69 | + APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} |
| 70 | + PROJECT_ID: ${{ secrets.GOOGLE_PROJECT_ID }} |
| 71 | + LOCATION_ZONE: "us-west1-a" |
| 72 | + CLUSTER_NAME: "github-actions-demo" |
| 73 | + WORKFLOW_YAML_PATH: "pipelines/workflow.yaml" # the argo workflow file relative to the repo's root. |
| 74 | + PARAMETER_FILE_PATH: "pipelines/params.yaml" # optional parameter file. |
| 75 | + SHA: ${{ steps.label.outputs.HEAD_SHA }} |
| 76 | + |
| 77 | + - name: Create Check |
| 78 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 79 | + run: | |
| 80 | + python3 action_files/create_check_run.py "in_progress" "Argo-Workflow" "ML Workflow For SHA $SHA" "Links [Argo Workflow]($ARGO_LINK) | [W&B Project](https://app.wandb.ai/$WANDB_ENTITY/$WANDB_PROJECT) | Docker: [hamelsmu/ml-cicd](https://cloud.docker.com/u/hamelsmu/repository/docker/hamelsmu/ml-cicd), [hamelsmu/ml-cicd-gpu](https://cloud.docker.com/u/hamelsmu/repository/docker/hamelsmu/ml-cicd-gpu)" " " |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + ARGO_LINK: ${{ steps.argo.outputs.WORKFLOW_URL }} |
| 84 | + WANDB_ENTITY: ${{ secrets.WANDB_ENTITY }} |
| 85 | + WANDB_PROJECT: ${{ secrets.WANDB_PROJECT }} |
| 86 | + SHA: ${{ steps.label.outputs.HEAD_SHA }} |
| 87 | + |
| 88 | + - name: Comment With Metadata |
| 89 | + if: steps.label.outputs.TRIGGERED == 'true' |
| 90 | + run: | |
| 91 | + bash action_files/pr_comment.sh "### [ML Workflow]($ARGO_LINK) For SHA $SHA has been instantiated.\n\nThe following Docker images were built and tagged with the SHA: \n - [hamelsmu/ml-cicd](https://cloud.docker.com/u/hamelsmu/repository/docker/hamelsmu/ml-cicd)\n - [hamelsmu/ml-cicd-gpu](https://cloud.docker.com/u/hamelsmu/repository/docker/hamelsmu/ml-cicd-gpu)\n\nCheck run \`Argo-Workflow\` created, with status pending completion of the workflow." |
| 92 | + env: |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + ARGO_LINK: ${{ steps.argo.outputs.WORKFLOW_URL }} |
| 95 | + WANDB_ENTITY: ${{ secrets.WANDB_ENTITY }} |
| 96 | + WANDB_PROJECT: ${{ secrets.WANDB_PROJECT }} |
| 97 | + ISSUE_NUMBER: ${{ steps.label.outputs.ISSUE_NUMBER }} |
| 98 | + SHA: ${{ steps.label.outputs.HEAD_SHA }} |
0 commit comments