|
| 1 | +# Continuous integration, including test and integration test |
| 2 | +name: Main Oura test |
| 3 | + |
| 4 | +# Run in master and dev branches and in all pull requests to those branches |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [ master, dev ] |
| 8 | + pull_request: |
| 9 | + branches: [ master, dev ] |
| 10 | + |
| 11 | +env: |
| 12 | + DOCKER_IMAGE: radarbase/kafka-connect-rest-oura-source |
| 13 | + |
| 14 | +jobs: |
| 15 | + # Build and test the code |
| 16 | + kotlin: |
| 17 | + # The type of runner that the job will run on |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 21 | + steps: |
| 22 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + |
| 25 | + - uses: actions/setup-java@v3 |
| 26 | + with: |
| 27 | + distribution: temurin |
| 28 | + java-version: 11 |
| 29 | + |
| 30 | + - name: Setup Gradle |
| 31 | + uses: gradle/gradle-build-action@v2 |
| 32 | + |
| 33 | + - name: Compile code |
| 34 | + run: gradle assemble |
| 35 | + working-directory: ./kafka-connect-oura-source |
| 36 | + |
| 37 | + # Gradle check |
| 38 | + - name: Check |
| 39 | + run: gradle check |
| 40 | + working-directory: ./kafka-connect-oura-source |
| 41 | + |
| 42 | + docker: |
| 43 | + # The type of runner that the job will run on |
| 44 | + runs-on: ubuntu-latest |
| 45 | + |
| 46 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 47 | + steps: |
| 48 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 49 | + - uses: actions/checkout@v3 |
| 50 | + |
| 51 | + - name: Docker build parameters |
| 52 | + id: docker_params |
| 53 | + run: | |
| 54 | + HAS_DOCKER_LOGIN=${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }} |
| 55 | + echo "has_docker_login=$HAS_DOCKER_LOGIN" >> $GITHUB_OUTPUT |
| 56 | + if [ "${{ github.event_name == 'pull_request' }}" = "true" ] || [ "$HAS_DOCKER_LOGIN" = "false" ]; then |
| 57 | + echo "push=false" >> $GITHUB_OUTPUT |
| 58 | + echo "load=true" >> $GITHUB_OUTPUT |
| 59 | + echo "platforms=linux/amd64" >> $GITHUB_OUTPUT |
| 60 | + else |
| 61 | + echo "push=true" >> $GITHUB_OUTPUT |
| 62 | + echo "load=false" >> $GITHUB_OUTPUT |
| 63 | + echo "platforms=linux/amd64,linux/arm64" >> $GITHUB_OUTPUT |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Cache Docker layers |
| 67 | + id: cache_buildx |
| 68 | + uses: actions/cache@v3 |
| 69 | + with: |
| 70 | + path: /tmp/.buildx-cache |
| 71 | + key: ${{ runner.os }}-buildx-${{ steps.docker_params.outputs.push }}-${{ hashFiles('**/Dockerfile', '**/*.gradle', 'gradle.properties', '.dockerignore', '*/src/main/**', 'docker/**') }} |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-buildx-${{ steps.docker_params.outputs.push }}- |
| 74 | + ${{ runner.os }}-buildx- |
| 75 | +
|
| 76 | + - name: Login to Docker Hub |
| 77 | + if: steps.docker_params.outputs.has_docker_login == 'true' |
| 78 | + uses: docker/login-action@v2 |
| 79 | + with: |
| 80 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 81 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 82 | + |
| 83 | + # Add Docker labels and tags |
| 84 | + - name: Docker meta |
| 85 | + id: docker_meta |
| 86 | + uses: docker/metadata-action@v4 |
| 87 | + with: |
| 88 | + images: ${{ env.DOCKER_IMAGE }} |
| 89 | + |
| 90 | + # Setup docker build environment |
| 91 | + - name: Set up QEMU |
| 92 | + uses: docker/setup-qemu-action@v2 |
| 93 | + |
| 94 | + - name: Set up Docker Buildx |
| 95 | + uses: docker/setup-buildx-action@v2 |
| 96 | + |
| 97 | + - name: Cache parameters |
| 98 | + id: cache-parameters |
| 99 | + run: | |
| 100 | + if [ "${{ steps.cache_buildx.outputs.cache-hit }}" = "true" ]; then |
| 101 | + echo "::set-output name=cache-to::" |
| 102 | + else |
| 103 | + echo "::set-output name=cache-to::type=local,dest=/tmp/.buildx-cache-new,mode=max" |
| 104 | + fi |
| 105 | +
|
| 106 | + - name: Build docker |
| 107 | + uses: docker/build-push-action@v3 |
| 108 | + with: |
| 109 | + file: ./kafka-connect-oura-source/Dockerfile |
| 110 | + context: . |
| 111 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 112 | + cache-to: ${{ steps.cache-parameters.outputs.cache-to }} |
| 113 | + platforms: ${{ steps.docker_params.outputs.platforms }} |
| 114 | + load: ${{ steps.docker_params.outputs.load }} |
| 115 | + push: ${{ steps.docker_params.outputs.push }} |
| 116 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 117 | + # Use runtime labels from docker_meta as well as fixed labels |
| 118 | + labels: | |
| 119 | + ${{ steps.docker_meta.outputs.labels }} |
| 120 | + maintainer=Pauline Conde <[email protected]>, Yatharth Ranjan <[email protected]> |
| 121 | + org.opencontainers.image.description=RADAR-base upload connector backend application |
| 122 | + org.opencontainers.image.authors=Pauline Conde <[email protected]>, Yatharth Ranjan <[email protected]> |
| 123 | + org.opencontainers.image.vendor=RADAR-base |
| 124 | + org.opencontainers.image.licenses=Apache-2.0 |
| 125 | +
|
| 126 | + - name: Pull docker image |
| 127 | + if: steps.docker_params.outputs.load == 'false' |
| 128 | + run: docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
| 129 | + |
| 130 | + - name: Inspect docker image |
| 131 | + run: | |
| 132 | + docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
| 133 | + docker run --rm ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} curl --version |
| 134 | +
|
| 135 | +
|
| 136 | + # https://github.com/docker/build-push-action/issues/252 |
| 137 | + # https://github.com/moby/buildkit/issues/1896 |
| 138 | + - name: Move docker build cache |
| 139 | + if: steps.cache_buildx.outputs.cache-hit != 'true' |
| 140 | + run: | |
| 141 | + rm -rf /tmp/.buildx-cache |
| 142 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
0 commit comments