-
Notifications
You must be signed in to change notification settings - Fork 347
Feature/docker ci cd #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feature/docker ci cd #544
Changes from all commits
6422cb2
35b9cfa
99d2b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Git | ||
| .git | ||
| .github | ||
| .gitignore | ||
|
|
||
| # Build artifacts | ||
| build/ | ||
| packaging/deb/ | ||
| packaging/rpm/ | ||
| packaging/windows/ | ||
|
|
||
| # Documentation | ||
| docs/ | ||
|
|
||
| # IDE & editor | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # Markdown (not needed in image) | ||
| *.md | ||
| LICENSE | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,127 @@ | ||||||
| name: Docker Test, Build & Push | ||||||
|
|
||||||
| on: | ||||||
| workflow_call: | ||||||
| secrets: | ||||||
| DOCKERHUB_USERNAME: | ||||||
| required: true | ||||||
| description: "Docker Hub username" | ||||||
| DOCKERHUB_TOKEN: | ||||||
| required: true | ||||||
| description: "Docker Hub access token" | ||||||
|
|
||||||
| env: | ||||||
| IMAGE_NAME: mirantis/cri-dockerd | ||||||
|
|
||||||
| jobs: | ||||||
| # ----------------------------------------------------------- | ||||||
| # Stage 1 – Run unit tests inside a Docker container | ||||||
| # ----------------------------------------------------------- | ||||||
| docker-test: | ||||||
| runs-on: ubuntu-latest | ||||||
| steps: | ||||||
| - name: Checkout | ||||||
| uses: actions/checkout@v3 | ||||||
|
|
||||||
| - name: Load environment | ||||||
| uses: c-py/action-dotenv-to-setenv@v4 | ||||||
| with: | ||||||
| env-file: .github/.env | ||||||
|
|
||||||
| - name: Set up Docker Buildx | ||||||
| uses: docker/setup-buildx-action@v3 | ||||||
|
|
||||||
| - name: Build test image | ||||||
| uses: docker/build-push-action@v6 | ||||||
| with: | ||||||
| context: . | ||||||
| file: ./Dockerfile.test | ||||||
| build-args: | | ||||||
| GO_VERSION=${{ env.GO_VERSION }} | ||||||
| push: false | ||||||
| load: true | ||||||
| tags: cri-dockerd-test:ci | ||||||
| cache-from: type=gha | ||||||
| cache-to: type=gha,mode=max | ||||||
|
|
||||||
| - name: Run unit tests in container | ||||||
| run: docker run --rm cri-dockerd-test:ci | ||||||
|
|
||||||
| # ----------------------------------------------------------- | ||||||
| # Stage 2 – Build multi-arch image & push to Docker Hub | ||||||
| # ----------------------------------------------------------- | ||||||
| docker-build-push: | ||||||
| runs-on: ubuntu-latest | ||||||
| needs: [docker-test] | ||||||
| permissions: | ||||||
| contents: read | ||||||
| packages: write | ||||||
| steps: | ||||||
| - name: Checkout | ||||||
| uses: actions/checkout@v3 | ||||||
| with: | ||||||
| fetch-depth: 0 # needed for git describe | ||||||
|
|
||||||
| - name: Load environment | ||||||
| uses: c-py/action-dotenv-to-setenv@v4 | ||||||
| with: | ||||||
| env-file: .github/.env | ||||||
|
|
||||||
| - name: Set version metadata | ||||||
| id: meta | ||||||
| run: | | ||||||
| VERSION=$(git describe --tags 2>/dev/null | sed 's/^v//' || echo "dev") | ||||||
|
||||||
| VERSION=$(git describe --tags 2>/dev/null | sed 's/^v//' || echo "dev") | |
| VERSION=$(git describe --tags 2>/dev/null) && VERSION=${VERSION#v} || VERSION=dev |
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docker-build-push job unconditionally sets push: true, which means it will push an image to Docker Hub on every PR event (since docker.yml is also called from PR.yml). This is likely unintended — PR builds should not publish images to the public registry. Consider conditionally setting push based on the GitHub event type, for example by adding push: ${{ github.event_name != 'pull_request' }}.
| push: true | |
| push: ${{ github.event_name != 'pull_request' }} |
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Print image digest" step incorrectly references steps.docker_meta.outputs.digest. The docker_meta step id refers to the docker/metadata-action@v5 step, which does not produce a digest output. The image digest is an output of the docker/build-push-action@v6 "Build and push" step. To fix this, add an id (e.g., id: build) to the "Build and push" step and then reference it as steps.build.outputs.digest.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||
| # syntax=docker/dockerfile:1 | ||||||||
|
|
||||||||
| # ---- Build Stage ---- | ||||||||
| ARG GO_VERSION=1.24.9 | ||||||||
| FROM golang:${GO_VERSION}-bookworm AS builder | ||||||||
|
|
||||||||
| ARG VERSION="" | ||||||||
| ARG REVISION="" | ||||||||
| ARG PRERELEASE="" | ||||||||
| ARG TARGETOS=linux | ||||||||
| ARG TARGETARCH=amd64 | ||||||||
|
|
||||||||
| WORKDIR /go/src/github.com/Mirantis/cri-dockerd | ||||||||
|
|
||||||||
| # Cache Go modules | ||||||||
| COPY go.mod go.sum ./ | ||||||||
| RUN go mod download | ||||||||
|
|
||||||||
| # Copy source | ||||||||
| COPY . . | ||||||||
|
|
||||||||
| # Build the binary | ||||||||
| RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath \ | ||||||||
| -ldflags "-s -w \ | ||||||||
| -X github.com/Mirantis/cri-dockerd/cmd/version.Version=${VERSION} \ | ||||||||
| -X github.com/Mirantis/cri-dockerd/cmd/version.PreRelease=${PRERELEASE} \ | ||||||||
| -X github.com/Mirantis/cri-dockerd/cmd/version.GitCommit=${REVISION}" \ | ||||||||
| -o /usr/local/bin/cri-dockerd | ||||||||
|
|
||||||||
| # ---- Test Stage ---- | ||||||||
| FROM builder AS test | ||||||||
| RUN go test ./... | ||||||||
|
|
||||||||
|
Comment on lines
+30
to
+33
|
||||||||
| # ---- Test Stage ---- | |
| FROM builder AS test | |
| RUN go test ./... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| # Dockerfile for running unit tests in CI | ||
| ARG GO_VERSION=1.24.9 | ||
| FROM golang:${GO_VERSION}-bookworm | ||
|
|
||
| WORKDIR /go/src/github.com/Mirantis/cri-dockerd | ||
|
|
||
| # Cache Go modules | ||
| COPY go.mod go.sum ./ | ||
| RUN go mod download | ||
|
|
||
| # Copy source | ||
| COPY . . | ||
|
|
||
| # Default command: run all unit tests | ||
| CMD ["go", "test", "-v", "./..."] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
vendor/directory is not excluded from the Docker build context in.dockerignore. Since the Dockerfiles usego mod downloadto fetch dependencies, thevendor/directory is not needed and unnecessarily inflates the build context. Addingvendor/to.dockerignorewould speed up Docker builds significantly.