Merge pull request #11 from HSLdevcom/issue/73261_enforce-running-tes… #43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build, Test & Push Base Images | |
| on: | |
| pull_request: | |
| branches: [ main ] | |
| push: | |
| branches: [ main ] | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| ci: | |
| name: CI – Lint, Build & Test Base Images | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: | |
| - dockerfilePath: java/jre | |
| version: "25" | |
| image: 25-java-jre | |
| - dockerfilePath: java/jdk | |
| version: "25" | |
| image: 25-java-jdk | |
| - dockerfilePath: node | |
| version: "22" | |
| image: 22-node | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Lint Dockerfile with hadolint | |
| uses: hadolint/hadolint-action@v3.1.0 | |
| with: | |
| config: .hadolint.yaml | |
| dockerfile: "./${{ matrix.dockerfilePath }}/Dockerfile" | |
| recursive: 'true' | |
| - name: Build base image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./${{ matrix.dockerfilePath }} | |
| push: false | |
| tags: ${{ matrix.image }}-test:latest | |
| - name: Build test image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./${{ matrix.dockerfilePath }}/test | |
| push: false | |
| tags: base-image-test:${{ matrix.image }}-test | |
| - name: Test test image (hello world) | |
| run: | | |
| docker run --rm base-image-test:${{ matrix.image }}-test echo "Test OK" | |
| cd: | |
| name: CD - Build & Publish Base Images | |
| runs-on: ubuntu-latest | |
| needs: ci | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) | |
| strategy: | |
| matrix: | |
| include: | |
| - dockerfilePath: jre/java | |
| version: "25" | |
| image: 25-java-jre | |
| - dockerfilePath: jdk/java | |
| version: "25" | |
| image: 25-java-jdk | |
| - dockerfilePath: node | |
| version: "22" | |
| image: 22-node | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Container Registry | |
| id: docker_login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.TRANSITDATA_DOCKERHUB_USER }} | |
| password: ${{ secrets.TRANSITDATA_DOCKERHUB_TOKEN }} | |
| - name: Check login output | |
| run: | | |
| docker info | |
| echo "Logged in registry: ${{ steps.docker_login.outputs.registry }}" | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: hsldevcom/infodevops-docker-base-images | |
| tags: | | |
| type=edge,prefix=${{ matrix.image }}-,enable={{is_default_branch}} | |
| type=semver,suffix=-${{ matrix.image }},pattern={{version}} | |
| type=semver,suffix=-${{ matrix.image }},pattern={{major}}.{{minor}} | |
| type=semver,suffix=-${{ matrix.image }},pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }} | |
| labels: | | |
| org.opencontainers.image.title=${{ matrix.image }} | |
| org.opencontainers.image.vendor=hsldevcom | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./${{ matrix.dockerfilePath }} | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |