|
| 1 | +name: Build and Push Docker Images to Harbor |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths-ignore: |
| 6 | + - '**.md' |
| 7 | + - 'docs/**' |
| 8 | + branches: |
| 9 | + - 'scalefield_v*' |
| 10 | + push: |
| 11 | + paths-ignore: |
| 12 | + - '**.md' |
| 13 | + - 'docs/**' |
| 14 | + branches: |
| 15 | + - 'scalefield_v*' |
| 16 | + workflow_dispatch: |
| 17 | + inputs: |
| 18 | + image_tags: |
| 19 | + description: 'Comma-separated list of tags' |
| 20 | + required: true |
| 21 | + type: string |
| 22 | + push_image: |
| 23 | + description: 'Push images to Harbor' |
| 24 | + required: false |
| 25 | + type: boolean |
| 26 | + default: true |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} |
| 30 | + cancel-in-progress: true |
| 31 | + |
| 32 | +jobs: |
| 33 | + build-and-push: |
| 34 | + name: Build and Push Docker Images to Harbor |
| 35 | + runs-on: ubuntu-latest |
| 36 | + timeout-minutes: 60 |
| 37 | + steps: |
| 38 | + - name: Checkout Repository |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Determine tags |
| 42 | + id: tags |
| 43 | + run: | |
| 44 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 45 | + echo "tags=${{ inputs.image_tags }}" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + FULL_SHA="${{ github.sha }}" |
| 48 | + SHORT_SHA="${FULL_SHA:0:7}" |
| 49 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 50 | + BRANCH_NAME="${{ github.head_ref }}" |
| 51 | + else |
| 52 | + BRANCH_NAME="${{ github.ref_name }}" |
| 53 | + fi |
| 54 | + BRANCH_NAME="${BRANCH_NAME//\//-}" |
| 55 | + echo "tags=${BRANCH_NAME},${FULL_SHA},${SHORT_SHA}" >> $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Generate Harbor tags |
| 59 | + id: harbor_tags |
| 60 | + run: | |
| 61 | + { |
| 62 | + echo "operator_tags<<EOF" |
| 63 | + IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" |
| 64 | + for tag in "${TAG_ARRAY[@]}"; do |
| 65 | + echo "${{ vars.HARBOR_ORG }}/scalefield/postgres-operator:${tag}" |
| 66 | + done |
| 67 | + echo "EOF" |
| 68 | + } >> "$GITHUB_OUTPUT" |
| 69 | + { |
| 70 | + echo "logical_backup_tags<<EOF" |
| 71 | + IFS=',' read -ra TAG_ARRAY <<< "${{ steps.tags.outputs.tags }}" |
| 72 | + for tag in "${TAG_ARRAY[@]}"; do |
| 73 | + echo "${{ vars.HARBOR_ORG }}/scalefield/logical-backup:${tag}" |
| 74 | + done |
| 75 | + echo "EOF" |
| 76 | + } >> "$GITHUB_OUTPUT" |
| 77 | +
|
| 78 | + - name: Debug tags |
| 79 | + run: | |
| 80 | + echo "::group::Operator Image Tags" |
| 81 | + echo "${{ steps.harbor_tags.outputs.operator_tags }}" |
| 82 | + echo "::endgroup::" |
| 83 | + echo "::group::Logical Backup Image Tags" |
| 84 | + echo "${{ steps.harbor_tags.outputs.logical_backup_tags }}" |
| 85 | + echo "::endgroup::" |
| 86 | +
|
| 87 | + - name: Set up QEMU |
| 88 | + uses: docker/setup-qemu-action@v3 |
| 89 | + |
| 90 | + - name: Set up Docker Buildx |
| 91 | + |
| 92 | + |
| 93 | + - name: Log in to Harbor |
| 94 | + uses: docker/login-action@v4 |
| 95 | + with: |
| 96 | + registry: ${{ vars.HARBOR_ORG }} |
| 97 | + username: ${{ vars.HARBOR_USERNAME }} |
| 98 | + password: ${{ secrets.HARBOR_PASSWORD }} |
| 99 | + |
| 100 | + - name: Build and push operator image |
| 101 | + id: build_operator |
| 102 | + uses: docker/build-push-action@v7 |
| 103 | + continue-on-error: true |
| 104 | + with: |
| 105 | + context: . |
| 106 | + file: docker/Dockerfile |
| 107 | + platforms: linux/amd64,linux/arm64 |
| 108 | + push: ${{ github.event_name != 'workflow_dispatch' || inputs.push_image }} |
| 109 | + tags: ${{ steps.harbor_tags.outputs.operator_tags }} |
| 110 | + build-args: BASE_IMAGE=alpine:3 |
| 111 | + cache-from: type=gha |
| 112 | + cache-to: type=gha,mode=max |
| 113 | + |
| 114 | + - name: Build and push logical-backup image |
| 115 | + id: build_logical_backup |
| 116 | + uses: docker/build-push-action@v7 |
| 117 | + continue-on-error: true |
| 118 | + with: |
| 119 | + context: logical-backup |
| 120 | + platforms: linux/amd64,linux/arm64 |
| 121 | + push: ${{ github.event_name != 'workflow_dispatch' || inputs.push_image }} |
| 122 | + tags: ${{ steps.harbor_tags.outputs.logical_backup_tags }} |
| 123 | + build-args: BASE_IMAGE=ubuntu:22.04 |
| 124 | + cache-from: type=gha |
| 125 | + cache-to: type=gha,mode=max |
| 126 | + |
0 commit comments