|
8 | 8 | pull_request: |
9 | 9 | branches: [ master, dev ] |
10 | 10 |
|
| 11 | +env: |
| 12 | + DOCKER_IMAGE: radarbase/radar-appserver |
| 13 | + |
11 | 14 | jobs: |
12 | 15 | # Build and test the code |
13 | 16 | build: |
|
47 | 50 | docker-compose -f src/integrationTest/resources/docker/docker-compose.yml up -d postgres managementportal |
48 | 51 | # Wait for services to start up. |
49 | 52 | sleep 50 |
| 53 | + - name: Install gpg secret key |
| 54 | + run: | |
| 55 | + cat <(echo -e "${{ secrets.GPG_SECRET_KEY }}") | gpg --batch --import |
| 56 | + gpg --list-secret-keys --keyid-format LONG |
| 57 | + - name: Decrypt google application credentials |
| 58 | + run: | |
| 59 | + gpg --pinentry-mode loopback --local-user "Yatharth Ranjan" --batch --yes --passphrase "${{ secrets.GPG_SECRET_KEY_PASSPHRASE }}" --output src/integrationTest/resources/google-credentials.json --decrypt src/integrationTest/resources/google-credentials.enc.gpg |
50 | 60 |
|
51 | 61 | # Gradle check |
52 | 62 | - name: Check |
53 | | - run: ./gradlew check |
| 63 | + run: GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/src/integrationTest/resources/google-credentials.json ./gradlew check |
| 64 | + |
| 65 | + # Check that the docker image builds correctly |
| 66 | + docker: |
| 67 | + # The type of runner that the job will run on |
| 68 | + runs-on: ubuntu-latest |
| 69 | + |
| 70 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 71 | + steps: |
| 72 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 73 | + - uses: actions/checkout@v2 |
| 74 | + |
| 75 | + - name: Login to Docker Hub |
| 76 | + uses: docker/login-action@v1 |
| 77 | + with: |
| 78 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 79 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 80 | + |
| 81 | + # Add Docker labels and tags |
| 82 | + - name: Docker meta |
| 83 | + id: docker_meta |
| 84 | + uses: crazy-max/ghaction-docker-meta@v2 |
| 85 | + with: |
| 86 | + images: ${{ env.DOCKER_IMAGE }} |
| 87 | + |
| 88 | + # Setup docker build environment |
| 89 | + - name: Set up QEMU |
| 90 | + uses: docker/setup-qemu-action@v1 |
| 91 | + |
| 92 | + - name: Set up Docker Buildx |
| 93 | + uses: docker/setup-buildx-action@v1 |
| 94 | + |
| 95 | + - name: Cache Docker layers |
| 96 | + id: cache-buildx |
| 97 | + uses: actions/cache@v2 |
| 98 | + with: |
| 99 | + path: /tmp/.buildx-cache |
| 100 | + key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '**/*.gradle.kts', 'gradle.properties', 'src/main/**') }} |
| 101 | + restore-keys: | |
| 102 | + ${{ runner.os }}-buildx- |
| 103 | +
|
| 104 | + - name: Cache parameters |
| 105 | + id: cache-parameters |
| 106 | + run: | |
| 107 | + if [ "${{ steps.cache-buildx.outputs.cache-hit }}" = "true" ]; then |
| 108 | + echo "::set-output name=cache-to::" |
| 109 | + else |
| 110 | + echo "::set-output name=cache-to::type=local,dest=/tmp/.buildx-cache-new,mode=max" |
| 111 | + fi |
| 112 | +
|
| 113 | + - name: Build docker |
| 114 | + uses: docker/build-push-action@v2 |
| 115 | + with: |
| 116 | + cache-from: type=local,src=/tmp/.buildx-cache |
| 117 | + cache-to: ${{ steps.cache-parameters.outputs.cache-to }} |
| 118 | + load: true |
| 119 | + tags: ${{ steps.docker_meta.outputs.tags }} |
| 120 | + # Use runtime labels from docker_meta as well as fixed labels |
| 121 | + labels: | |
| 122 | + ${{ steps.docker_meta.outputs.labels }} |
| 123 | + maintainer=Yatharth Ranjan <yatharth.ranjan@kcl.ac.uk>, Pauline Conde <pauline.conde@kcl.ac.uk> |
| 124 | + org.opencontainers.image.authors=Yatharth Ranjan <yatharth.ranjan@kcl.ac.uk>, Pauline Conde <pauline.conde@kcl.ac.uk> |
| 125 | + org.opencontainers.image.vendor=RADAR-base |
| 126 | + org.opencontainers.image.licenses=Apache-2.0 |
| 127 | +
|
| 128 | + - name: Inspect docker image |
| 129 | + run: docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
| 130 | + |
| 131 | + # Push the image on the dev and master branches |
| 132 | + - name: Push image |
| 133 | + if: ${{ github.event_name != 'pull_request' }} |
| 134 | + run: docker push ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} |
| 135 | + |
| 136 | + # Temp fix |
| 137 | + # https://github.com/docker/build-push-action/issues/252 |
| 138 | + # https://github.com/moby/buildkit/issues/1896 |
| 139 | + - name: Move docker build cache |
| 140 | + if: steps.cache-buildx.outputs.cache-hit != 'true' |
| 141 | + run: | |
| 142 | + rm -rf /tmp/.buildx-cache |
| 143 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 144 | + |
| 145 | + |
| 146 | + |
0 commit comments