|
| 1 | +name: Push docker artifacts to customer (must be run in infrastructure-k8s) |
| 2 | +run-name: Push ${{ inputs.repository }}:${{ inputs.image_tag }} docker artifacts to ${{ inputs.customer }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + repository: |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + customer: |
| 11 | + type: string |
| 12 | + required: true |
| 13 | + customer_json: |
| 14 | + type: string |
| 15 | + required: true |
| 16 | + image_tag: |
| 17 | + type: string |
| 18 | + required: true |
| 19 | + runs_on: |
| 20 | + type: string |
| 21 | + required: false |
| 22 | + default: "ubuntu-22.04" |
| 23 | + secrets: |
| 24 | + DATAVISYN_BOT_REPO_TOKEN: |
| 25 | + required: false |
| 26 | + CHECKOUT_TOKEN: |
| 27 | + required: false |
| 28 | + DV_AWS_ECR_SECRETS: |
| 29 | + required: false |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: "${{ github.workflow }}-${{ github.ref || github.head_ref }}-${{ inputs.repository }}-${{ inputs.customer }}-${{ inputs.image_tag }}" |
| 33 | + cancel-in-progress: true |
| 34 | + |
| 35 | +env: |
| 36 | + WORKFLOW_BRANCH: "main" |
| 37 | + |
| 38 | +permissions: |
| 39 | + contents: read |
| 40 | + id-token: write |
| 41 | + |
| 42 | +jobs: |
| 43 | + post-build: |
| 44 | + name: Push ${{ inputs.repository }}:${{ inputs.image_tag }} docker artifacts to ${{ inputs.customer }} |
| 45 | + runs-on: ${{ inputs.runs_on || 'ubuntu-22.04' }} |
| 46 | + |
| 47 | + steps: |
| 48 | + - name: Checkout repository (must be run in infrastructure-k8s) |
| 49 | + uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }} |
| 52 | + |
| 53 | + - name: Checkout github-workflows repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + repository: datavisyn/github-workflows |
| 57 | + ref: ${{ env.WORKFLOW_BRANCH }} |
| 58 | + path: ./tmp/github-workflows |
| 59 | + |
| 60 | + - name: Extract customer from payload |
| 61 | + uses: actions/github-script@v7 |
| 62 | + id: get-customer |
| 63 | + with: |
| 64 | + script: | |
| 65 | + const customer = JSON.parse(process.env.CUSTOMER_JSON); |
| 66 | +
|
| 67 | + const filteredRepositories = customer.repositories.filter(repo => !repo.skip); |
| 68 | +
|
| 69 | + // Comma separated list of source images, incl. registry, repository and tag |
| 70 | + const sourceImages = filteredRepositories.map(repo => `${process.env.SOURCE_ECR_REGISTRY}/${repo.source_repository}:${repo.source_image_tag || process.env.IMAGE_TAG}`).join(','); |
| 71 | + const destinationImages = filteredRepositories.map(repo => `${customer.registry}/${repo.target_repository}:${repo.target_image_tag || process.env.IMAGE_TAG}`).join(','); |
| 72 | +
|
| 73 | + const result = { |
| 74 | + customer, |
| 75 | + skip: !!customer.skip, |
| 76 | + source_images: sourceImages, |
| 77 | + destination_images: destinationImages |
| 78 | + }; |
| 79 | + console.log(result); |
| 80 | + return result; |
| 81 | + env: |
| 82 | + SOURCE_ECR_REGISTRY: ${{ vars.DV_AWS_ECR_REGISTRY }} |
| 83 | + CUSTOMER_JSON: ${{ inputs.customer_json }} |
| 84 | + CUSTOMER: ${{ inputs.customer }} |
| 85 | + IMAGE_TAG: ${{ inputs.image_tag }} |
| 86 | + |
| 87 | + - name: Get dv image aws config |
| 88 | + if: ${{ fromJson(steps.get-customer.outputs.result).skip != true }} |
| 89 | + id: get-dv-aws-image-config |
| 90 | + uses: ./.github/actions/get-aws-config |
| 91 | + with: |
| 92 | + aws_config: ${{ secrets.DV_AWS_ECR_SECRETS }} |
| 93 | + |
| 94 | + - name: Get image aws config |
| 95 | + if: ${{ fromJson(steps.get-customer.outputs.result).skip != true }} |
| 96 | + id: get-aws-image-config |
| 97 | + uses: ./.github/actions/get-aws-config |
| 98 | + with: |
| 99 | + aws_config: ${{ secrets[fromJson(steps.get-customer.outputs.result).customer.secret_key] }} |
| 100 | + |
| 101 | + - name: Push images |
| 102 | + if: ${{ fromJson(steps.get-customer.outputs.result).skip != true }} |
| 103 | + id: pull-push-image |
| 104 | + uses: ./.github/actions/pull-push-image |
| 105 | + with: |
| 106 | + source_aws_role: ${{ steps.get-dv-aws-image-config.outputs.aws_role }} |
| 107 | + source_aws_region: ${{ steps.get-dv-aws-image-config.outputs.aws_region }} |
| 108 | + source_images: ${{ fromJson(steps.get-customer.outputs.result).source_images }} |
| 109 | + destination_aws_role: ${{ steps.get-aws-image-config.outputs.aws_role }} |
| 110 | + destination_aws_region: ${{ steps.get-aws-image-config.outputs.aws_region }} |
| 111 | + destination_aws_access_key_id: ${{ steps.get-aws-image-config.outputs.aws_access_key_id }} |
| 112 | + destination_aws_secret_access_key: ${{ steps.get-aws-image-config.outputs.aws_secret_access_key }} |
| 113 | + destination_images: ${{ fromJson(steps.get-customer.outputs.result).destination_images }} |
0 commit comments