diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..949aeef --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "Dockerfile", + "build": { + "context": "..", + "target": "devcontainer", + "dockerfile": "../Dockerfile" + }, + "customizations": { + "vscode": { + "extensions": [ + "golang.go", + "github.copilot", + "github.vscode-github-actions" + ] + } + } +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5c705c4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: test + +on: + pull_request: + push: + branches: + - 'master' + tags: + - 'v*' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Test + uses: docker/bake-action@v5 + with: + targets: test \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..07014ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM --platform=$BUILDPLATFORM golang:1.23-bullseye AS base + +# devcontainer +FROM base AS gopls +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + GOBIN=/build/ GO111MODULE=on go install "golang.org/x/tools/gopls@latest" \ + && /build/gopls version + +FROM base AS devcontainer +COPY --from=gopls /build/gopls /usr/local/bin/gopls + +# deps +FROM base AS deps + +WORKDIR /go/src + +RUN --mount=type=bind,src=./go.mod,target=./go.mod \ + --mount=type=bind,src=./go.sum,target=./go.sum \ + go mod download + +# test +FROM deps AS test + +ARG TARGETOS +ARG TARGETARCH +RUN --mount=type=bind,target=/go/src \ + --mount=type=cache,target=/root/.cache/go-build \ + go test -v diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..0803773 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,9 @@ +group "default" { + targets = ["test"] +} + +target "test" { + target = "test" + output = ["type=cacheonly"] +} +