|
| 1 | +name: Build and push Docker image |
| 2 | +permissions: |
| 3 | + contents: read |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + tags: |
| 9 | + - "*" |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-push-image: |
| 20 | + name: Build and push Docker image |
| 21 | + runs-on: [matterlabs-ci-runner] |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 24 | + with: |
| 25 | + submodules: recursive |
| 26 | + |
| 27 | + - name: Set git SHA |
| 28 | + id: git_sha |
| 29 | + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 30 | + |
| 31 | + - name: Set Docker tag |
| 32 | + id: docker_tag |
| 33 | + run: | |
| 34 | + ts=$(date +%s%N | cut -b1-13) |
| 35 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 36 | + echo "tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT |
| 37 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 38 | + echo "tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT |
| 39 | + elif [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 40 | + echo "tag=none" >> $GITHUB_OUTPUT |
| 41 | + else |
| 42 | + echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}, only refs/heads/, refs/tags/ and pull_request are supported." |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.0 |
| 48 | + |
| 49 | + - name: Log in to Docker Hub |
| 50 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 51 | + with: |
| 52 | + username: ${{ secrets.DOCKERHUB_USER }} |
| 53 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 54 | + |
| 55 | + - name: Login to GAR |
| 56 | + run: | |
| 57 | + gcloud auth configure-docker us-docker.pkg.dev -q |
| 58 | +
|
| 59 | + - name: Build and push oidc-server image |
| 60 | + id: docker_build_oidc |
| 61 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + file: Dockerfile |
| 65 | + target: oidc-server |
| 66 | + push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }} |
| 67 | + tags: | |
| 68 | + matterlabs/sso-oidc-salt:${{ steps.docker_tag.outputs.tag }} |
| 69 | + matterlabs/sso-oidc-salt:latest |
| 70 | + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/sso-oidc-salt:${{ steps.docker_tag.outputs.tag }} |
| 71 | + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/sso-oidc-salt:latest |
| 72 | +
|
| 73 | + - name: Build and push key-registry image |
| 74 | + id: docker_build_key_registry |
| 75 | + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 |
| 76 | + with: |
| 77 | + context: . |
| 78 | + file: Dockerfile |
| 79 | + target: key-registry |
| 80 | + push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }} |
| 81 | + tags: | |
| 82 | + matterlabs/sso-oidc-key-updater:${{ steps.docker_tag.outputs.tag }} |
| 83 | + matterlabs/sso-oidc-key-updater:latest |
| 84 | + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/sso-oidc-key-updater:${{ steps.docker_tag.outputs.tag }} |
| 85 | + us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/sso-oidc-key-updater:latest |
| 86 | +
|
| 87 | + - name: Print image digest to summary |
| 88 | + run: | |
| 89 | + echo "OIDC Server Image tag: ${{ steps.docker_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY |
| 90 | + echo "Key Registry Image tag: ${{ steps.docker_tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments