master
yml 84 lines 2.95 KB
Raw
1 # This workflow performs a quick Docker build check on PRs and pushes to master.
2 # It builds the Docker image and runs a basic smoke test to ensure the image works.
3 # This is a lightweight check - for full multi-platform builds and publishing, see docker-image.yml
4 name: Docker Check
5
6 on:
7 workflow_dispatch:
8 pull_request:
9 paths-ignore:
10 - '**/*.md'
11 push:
12 branches:
13 - 'master'
14
15 concurrency:
16 group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }}
17 cancel-in-progress: true
18
19 jobs:
20 lint:
21 if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch'
22 runs-on: ubuntu-latest
23 timeout-minutes: 5
24 steps:
25 - uses: actions/checkout@v6
26 - uses: hadolint/hadolint-action@v3.3.0
27 with:
28 dockerfile: Dockerfile
29 failure-threshold: warning
30 verbose: true
31 format: tty
32
33 # Guard rail: the Dockerfile ARG default is what `docker build .` uses
34 # locally without --build-arg. CI overrides it from go.mod, but the
35 # default must stay in sync so local builds and the published image use
36 # the same Go toolchain.
37 - name: Verify Dockerfile GO_VERSION default matches go.mod
38 run: |
39 GO_MOD_VERSION=$(awk '/^go [0-9]/ {print $2; exit}' go.mod)
40 DOCKERFILE_VERSION=$(awk -F= '/^ARG GO_VERSION=/ {print $2; exit}' Dockerfile)
41 if [ "$GO_MOD_VERSION" != "$DOCKERFILE_VERSION" ]; then
42 echo "::error file=Dockerfile::go.mod has 'go ${GO_MOD_VERSION}' but Dockerfile default ARG GO_VERSION=${DOCKERFILE_VERSION}. Update the Dockerfile default to match go.mod."
43 exit 1
44 fi
45 echo "OK: both pinned to ${GO_MOD_VERSION}"
46
47 build:
48 if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch'
49 runs-on: ubuntu-latest
50 timeout-minutes: 10
51 env:
52 IMAGE_NAME: ipfs/kubo
53 WIP_IMAGE_TAG: wip
54 defaults:
55 run:
56 shell: bash
57 steps:
58 - uses: actions/checkout@v6
59
60 - name: Set up Docker Buildx
61 uses: docker/setup-buildx-action@v4
62
63 # Mirror the publish workflow: pull the Go version from go.mod so the
64 # PR check builds with the same toolchain that the published image uses.
65 - name: Read Go version from go.mod
66 id: go
67 run: echo "version=$(awk '/^go [0-9]/ {print $2; exit}' go.mod)" >> "$GITHUB_OUTPUT"
68
69 - name: Build Docker image with BuildKit
70 uses: docker/build-push-action@v7
71 with:
72 context: .
73 push: false
74 load: true
75 tags: ${{ env.IMAGE_NAME }}:${{ env.WIP_IMAGE_TAG }}
76 build-args: |
77 GO_VERSION=${{ steps.go.outputs.version }}
78 cache-from: |
79 type=gha
80 type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
81 cache-to: type=gha,mode=max
82
83 - name: Test Docker image
84 run: docker run --rm $IMAGE_NAME:$WIP_IMAGE_TAG --version