diff --git a/.github/workflows/publish_images.yaml b/.github/workflows/publish_images.yaml index 9ef0f249..73b7a107 100644 --- a/.github/workflows/publish_images.yaml +++ b/.github/workflows/publish_images.yaml @@ -1,21 +1,17 @@ name: Publish images on: + workflow_dispatch: workflow_run: workflows: ["X-Road-Catalog tests"] types: [completed] - branches: [develop, XRDCAT-28-**] - workflow_dispatch: {} + branches: [develop] env: REGISTRY: ghcr.io - XROAD_HOME: ${{ github.workspace }} jobs: BuildAndPublish: - name: Setup Environment - if: ${{ github.event.workflow_run.conclusion == 'success' }} + name: Build and publish docker images + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-24.04 - strategy: - matrix: - service: [collector, lister] steps: - name: Checkout source code uses: actions/checkout@v4 @@ -35,26 +31,50 @@ jobs: add-job-summary-as-pr-comment: always - name: Build JARs (skipping tests) run: ./gradlew --no-daemon build -x test + - name: List JAR files + run: ls -lah xroad-catalog-collector/build/libs xroad-catalog-lister/build/libs - name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push xrddev-catalog-${{ matrix.service }}'s Docker Image + - name: Build and push xrddev-catalog-collector's Docker Image uses: docker/build-push-action@v6 with: - context: ${{ github.workspace }}/docker/${{ matrix.service }} + context: ${{ github.workspace }} + file: ${{ github.workspace }}/docker/collector/Dockerfile push: true - tags: ghcr.io/nordic-institute/xrddev-catalog-${{ matrix.service }}:latest - - name: Clean old ${{ matrix.service }} images - uses: snok/container-retention-policy@v2 + tags: ghcr.io/nordic-institute/xrddev-catalog-collector:latest + - name: Build and push xrddev-catalog-lister's Docker Image + uses: docker/build-push-action@v6 + with: + context: ${{ github.workspace }} + file: ${{ github.workspace }}/docker/lister/Dockerfile + push: true + tags: ghcr.io/nordic-institute/xrddev-catalog-lister:latest + + CleanOldImages: + name: Clean old docker images + if: ${{ needs.BuildAndPublish.result == 'success' }} + needs: BuildAndPublish + runs-on: ubuntu-24.04 + steps: + - name: Clean old xrddev-catalog-collector's Docker Images + uses: snok/container-retention-policy@v3.0.0 + with: + account: nordic-institute + image-names: xrddev-catalog-collector + cut-off: 1w + timestamp-to-use: created_at + keep-n-most-recent: 1 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Clean old xrddev-catalog-lister's Docker Images + uses: snok/container-retention-policy@v3.0.0 with: - image-names: xrddev-catalog-${{ matrix.service }} - cut-off: 1 week ago UTC + account: nordic-institute + image-names: xrddev-catalog-lister + cut-off: 1w timestamp-to-use: created_at - account-type: org - org-name: nordic-institute - keep-at-least: 1 - token-type: github-token + keep-n-most-recent: 1 token: ${{ secrets.GITHUB_TOKEN }}