Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Unix4ever committed Feb 16, 2021
0 parents commit 77685fc
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .conform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
policies:
- type: commit
spec:
headerLength: 89
dco: true
gpg: false
imperative: true
maximumOfOneCommit: true
requireCommitBody: true
conventional:
types:
- chore
- docs
- perf
- refactor
- style
- test
scopes:
- '*'
- type: license
spec:
skipPaths:
- .git/
includeSuffixes:
- .go
header: |
// CHANGE ME.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*
!api
!hack
!internal
!pkg
!go.mod
!go.sum
!*.go
!README.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_out
76 changes: 76 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# syntax = docker/dockerfile-upstream:1.1.4-experimental

# The base target provides the base for running various tasks against the source
# code.

FROM golang:1.13 AS base
ENV GO111MODULE on
ENV GOPROXY https://proxy.golang.org
ENV CGO_ENABLED 0
WORKDIR /tmp
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /go/bin v1.23.3
RUN cd $(mktemp -d) \
&& go mod init tmp \
&& go get mvdan.cc/gofumpt/gofumports
WORKDIR /src
COPY ./go.mod ./
COPY ./go.sum ./
RUN go mod download
RUN go mod verify
COPY ./ ./
RUN go list -mod=readonly all >/dev/null
RUN ! go mod tidy -v 2>&1 | grep .

# The test target performs tests on the source code.

FROM base AS unit-tests-runner
ARG PKGS
RUN --mount=type=cache,id=testspace,target=/tmp --mount=type=cache,target=/root/.cache/go-build go test -v -covermode=atomic -coverprofile=coverage.txt -count 1 ${PKGS}

FROM scratch AS unit-tests
COPY --from=unit-tests-runner /src/coverage.txt /coverage.txt

# The unit-tests-race target performs tests with race detector.

FROM base AS unit-tests-race
ENV CGO_ENABLED 1
ARG PKGS
RUN --mount=type=cache,target=/root/.cache/go-build go test -v -count 1 -race ${PKGS}

# The lint target performs linting on the source code.

FROM base AS lint-go
ENV GOGC=50
RUN --mount=type=cache,target=/root/.cache/go-build /go/bin/golangci-lint run
ARG MODULE
RUN FILES="$(gofumports -l -local ${MODULE} .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local ${MODULE} .':\n${FILES}"; exit 1)

# The fmt target formats the source code.

FROM base AS fmt-build
ARG MODULE
RUN gofumports -w -local ${MODULE} .

FROM scratch AS fmt
COPY --from=fmt-build /src /

# The markdownlint target performs linting on Markdown files.

FROM node:8.16.1-alpine AS lint-markdown
RUN npm install -g markdownlint-cli
RUN npm i sentences-per-line
WORKDIR /src
COPY --from=base /src .
RUN markdownlint --rules /node_modules/sentences-per-line/index.js .

# The container target builds the container image.

FROM base AS binary
RUN --mount=type=cache,target=/root/.cache/go-build GOOS=linux go build -ldflags "-s -w" -o /CHANGEME
RUN chmod +x /CHANGEME

FROM scratch AS container
COPY --from=docker.io/autonomy/ca-certificates:v0.1.0 / /
COPY --from=docker.io/autonomy/fhs:v0.1.0 / /
COPY --from=binary /CHANGEME /CHANGEME
ENTRYPOINT [ "/CHANGEME" ]

0 comments on commit 77685fc

Please sign in to comment.