Skip to content

Commit

Permalink
ci: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislbr committed Nov 11, 2021
1 parent 16caf52 commit 92ea594
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ Dockerfile
LICENSE
Makefile
README.md
test
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Get git tag
run: echo "GIT_TAG=`echo $(git describe --tags --abbrev=0)`" >> $GITHUB_ENV
- name: Build image
run: docker build -t "$IMAGE_NAME":"$GIT_TAG" -t "$IMAGE_NAME":latest .
run: DOCKER_BUILDKIT=1 docker build -t "$IMAGE_NAME":"$GIT_TAG" -t "$IMAGE_NAME":latest --target=prod .
- name: Log in
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Push image
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
with:
go-version: 1.17
- name: Test
run: make test
run: sed -i "s|"dist"|"test/public"|g" gss.go && go test
16 changes: 13 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
FROM golang:1.17-alpine AS build
WORKDIR /
FROM golang:1.17-alpine AS base
WORKDIR /gss
COPY go.mod go.sum ./
RUN go mod download
RUN go mod verify
COPY . ./

FROM base AS ci
RUN apk add build-base
RUN go install mvdan.cc/gofumpt@latest
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

FROM base AS build
ENV CGO_ENABLED=0
ENV GO111MODULE=on
ENV GOARCH=amd64
ENV GOOS=linux
RUN go build -o gss -ldflags="-s -w" gss.go

FROM scratch
FROM scratch AS prod
USER nobody:nobody
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ run-default: build

run-yaml: build
@docker run --rm -p 8080:80 -v $$PWD/test/gss.yaml:/gss.yaml -v $$PWD/test/public:/dist lewislbr/gss:test

test:
@sed -i "" "s|"dist"|"test/public"|g" gss.go
@go test
@sed -i "" "s|"test/public"|"dist"|g" gss.go
10 changes: 6 additions & 4 deletions ready.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
tasks:
- name: build ci image
command: docker build -t lewislbr/gss:ci --target=ci .
- name: format
command: gofumpt -extra -l -w .
command: docker run --rm -v $(pwd):/app -w /app lewislbr/gss:ci gofumpt -extra -l -w .
- name: lint
command: golangci-lint run --allow-parallel-runners --timeout 60s
command: docker run --rm -v $(pwd):/app -w /app lewislbr/gss:ci golangci-lint run --allow-parallel-runners --timeout 60s
- name: vet
command: go vet ./...
command: docker run --rm -v $(pwd):/app -w /app lewislbr/gss:ci go vet ./...
- name: test
command: go test ./... -count 1
command: sed -i "" "s|"dist"|"test/public"|g" gss.go && docker run --rm -v $(pwd):/app -w /app lewislbr/gss:ci go test; sed -i "" "s|"test/public"|"dist"|g" gss.go

0 comments on commit 92ea594

Please sign in to comment.