|
| 1 | +--- |
| 2 | +name: "Build & test Docker image" |
| 3 | +description: "Builds a Docker image, then runs tests (goss)" |
| 4 | + |
| 5 | +inputs: |
| 6 | + image: |
| 7 | + description: "Image name (subdir containing Dockerfile)" |
| 8 | + required: true |
| 9 | + version: |
| 10 | + description: "Image version/tag" |
| 11 | + required: true |
| 12 | + target: |
| 13 | + description: "Dockerfile target to build" |
| 14 | + required: false |
| 15 | + default: final |
| 16 | + build-args: |
| 17 | + description: "Build arguments to pass along to Docker" |
| 18 | + required: false |
| 19 | + context: |
| 20 | + description: "Build context path (defaults to the image path)" |
| 21 | + required: false |
| 22 | + |
| 23 | +runs: |
| 24 | + using: "composite" |
| 25 | + steps: |
| 26 | + - name: Install Goss |
| 27 | + shell: bash |
| 28 | + run: | |
| 29 | + curl -sS -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss |
| 30 | + curl -sS -L https://github.com/goss-org/goss/releases/latest/download/dgoss -o /usr/local/bin/dgoss |
| 31 | + chmod +x /usr/local/bin/goss /usr/local/bin/dgoss |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v3 |
| 34 | + with: |
| 35 | + driver-opts: network=host |
| 36 | + - name: Build base image (if needed) |
| 37 | + id: build-base |
| 38 | + uses: ./.github/actions/prebuild-base |
| 39 | + with: |
| 40 | + image: ${{ inputs.image }} |
| 41 | + build-args: ${{ inputs.build-args }} |
| 42 | + - name: Build image |
| 43 | + uses: docker/build-push-action@v6 |
| 44 | + with: |
| 45 | + context: ${{ inputs.context != '' && inputs.context || format('./{0}/', inputs.image) }} |
| 46 | + file: ./${{ inputs.image }}/Dockerfile |
| 47 | + load: true |
| 48 | + tags: ${{ inputs.image }}:${{ inputs.version }} |
| 49 | + target: ${{ inputs.target }} |
| 50 | + build-args: ${{ inputs.build-args }} |
| 51 | + build-contexts: ${{ steps.build-base.outputs.build-context }} |
| 52 | + cache-from: type=gha |
| 53 | + cache-to: type=gha,mode=max |
| 54 | + - name: Run goss tests |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + ./tests/run-tests.sh ${{ inputs.image }}:${{ inputs.version }} ${{ inputs.target }} |
0 commit comments