diff --git a/.github/workflows/build-images.yaml b/.github/workflows/build-images.yaml new file mode 100644 index 00000000..7629559b --- /dev/null +++ b/.github/workflows/build-images.yaml @@ -0,0 +1,139 @@ +name: Build and Publish Images + +on: + push: + branches: + - main + - "release-*" + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + workflow_dispatch: + +env: + IMG_TAGS: ${{ github.sha }} ${{ github.ref_name }} + IMG_REGISTRY_HOST: quay.io + IMG_REGISTRY_ORG: kuadrant + IMG_REGISTRY_REPO: kuadrant-dns-operator + MAIN_BRANCH_NAME: main + OPERATOR_NAME: kuadrant-dns-operator + +jobs: + build: + name: Build and Push image + runs-on: ubuntu-20.04 + outputs: + build-image: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ steps.build-image.outputs.image }}:${{ github.sha }} + build-tags: ${{ steps.build-image.outputs.tags }} + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Add latest tag + if: ${{ github.ref_name == env.MAIN_BRANCH_NAME }} + id: add-latest-tag + run: | + echo "IMG_TAGS=latest ${{ env.IMG_TAGS }}" >> $GITHUB_ENV + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.OPERATOR_NAME }} + tags: ${{ env.IMG_TAGS }} + dockerfiles: | + ./Dockerfile + + - name: Print Build Info + run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}" + + - name: Push Image + if: github.repository_owner == 'kuadrant' + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }} + username: ${{ secrets.IMG_REGISTRY_USERNAME }} + password: ${{ secrets.IMG_REGISTRY_TOKEN }} + + - name: Print Image URL + run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" + + build-bundle: + name: Build and Push bundle image + needs: [build] + runs-on: ubuntu-20.04 + outputs: + bundle-image: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }}/${{ steps.build-image.outputs.image }}:${{ github.sha }} + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Run make bundle + run: make bundle IMG=${{ needs.build.outputs.build-image }} + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.OPERATOR_NAME }}-bundle + tags: ${{ needs.build.outputs.build-tags }} + dockerfiles: | + ./bundle.Dockerfile + + - name: Print Build Info + run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}" + + - name: Push Image + if: github.repository_owner == 'kuadrant' + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }} + username: ${{ secrets.IMG_REGISTRY_USERNAME }} + password: ${{ secrets.IMG_REGISTRY_TOKEN }} + + - name: Print Image URL + run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" + + build-catalog: + name: Build and Push catalog image + needs: [build, build-bundle] + runs-on: ubuntu-20.04 + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Run make catalog-build + run: make catalog-build BUNDLE_IMG=${{ needs.build-bundle.outputs.bundle-image }} + + - name: Build Image + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.OPERATOR_NAME }}-catalog + tags: ${{ needs.build.outputs.build-tags }} + context: ./tmp/catalog + dockerfiles: | + ./tmp/catalog/index.Dockerfile + + - name: Print Build Info + run: echo "Image = ${{ steps.build-image.outputs.image }}, Tags = ${{ steps.build-image.outputs.tags }}" + + - name: Push Image + if: github.repository_owner == 'kuadrant' + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.IMG_REGISTRY_HOST }}/${{ env.IMG_REGISTRY_ORG }} + username: ${{ secrets.IMG_REGISTRY_USERNAME }} + password: ${{ secrets.IMG_REGISTRY_TOKEN }} + + - name: Print Image URL + run: echo "Image pushed to ${{ steps.push-to-quay.outputs.registry-paths }}" diff --git a/.gitignore b/.gitignore index 7f02333d..a9b45ed2 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ Dockerfile.cross *.swp *.swo *~ + +# Temporary files and directories +tmp diff --git a/Makefile b/Makefile index eec2cee4..aad38cc6 100644 --- a/Makefile +++ b/Makefile @@ -302,7 +302,7 @@ bundle-push: ## Push the bundle image. $(MAKE) docker-push IMG=$(BUNDLE_IMG) .PHONY: opm -OPM = ./bin/opm +OPM = $(LOCALBIN)/opm opm: ## Download opm locally if necessary. ifeq (,$(wildcard $(OPM))) ifeq (,$(shell which opm 2>/dev/null)) @@ -335,7 +335,9 @@ endif # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator .PHONY: catalog-build catalog-build: opm ## Build a catalog image. - $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) + mkdir -p tmp/catalog + cd tmp/catalog && $(OPM) index add --container-tool docker --mode semver --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) --generate + cd tmp/catalog && docker build -t $(CATALOG_IMG) -f index.Dockerfile . # Push the catalog image. .PHONY: catalog-push