Added dockerfile

This commit is contained in:
Marcus Noble 2020-10-17 20:57:26 +01:00
parent 38e0d61a5b
commit 845cac2d5a
2 changed files with 46 additions and 32 deletions

22
Dockerfile Normal file
View File

@ -0,0 +1,22 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.14-alpine as builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
WORKDIR /app/
RUN apk update && apk add --no-cache git && adduser -D -g '' gopher && apk add -U --no-cache ca-certificates
ADD go.mod go.sum ./
RUN go mod download
ADD . .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o gopherss .
FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch
WORKDIR /app/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /app/gopherss /app/gopherss
COPY ./web /app/web/
USER gopher
ENTRYPOINT ["/app/gopherss"]

View File

@ -1,65 +1,57 @@
.DEFAULT_GOAL := default .DEFAULT_GOAL := default
IMAGE ?= docker.cloud.cluster.fun/private/${REPO_NAME_LOWER}:latest IMAGE ?= docker.cluster.fun/averagemarcus/gopherss:latest
PLATFORMS ?= linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
export DOCKER_CLI_EXPERIMENTAL=enabled
.PHONY: test # Run all tests, linting and format checks .PHONY: test # Run all tests, linting and format checks
test: lint check-format run-tests test: lint check-format run-tests
.PHONY: lint # Perform lint checks against code .PHONY: lint # Perform lint checks against code
lint: lint:
@echo "⚠️ 'lint' unimplemented" @go vet && golint -set_exit_status ./...
# GO Projects
# @go vet && golint -set_exit_status ./...
.PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found .PHONY: check-format # Checks code formatting and returns a non-zero exit code if formatting errors found
check-format: check-format:
@echo "⚠️ 'check-format' unimplemented" @gofmt -e -l .
# GO Projects
# @gofmt -e -l .
.PHONY: format # Performs automatic format fixes on all code .PHONY: format # Performs automatic format fixes on all code
format: format:
@echo "⚠️ 'format' unimplemented" @gofmt -s -w .
# GO Projects
# @gofmt -s -w .
.PHONY: run-tests # Runs all tests .PHONY: run-tests # Runs all tests
run-tests: run-tests:
@echo "⚠️ 'run-tests' unimplemented" @go test
# GO Projects
# @go test
# Node Projects
# @npm test
.PHONY: fetch-deps # Fetch all project dependencies .PHONY: fetch-deps # Fetch all project dependencies
fetch-deps: fetch-deps:
@echo "⚠️ 'fetch-deps' unimplemented" @go mod tidy
# GO Projects
# @go mod tidy
# Node Projects
# @npm install
.PHONY: build # Build the project .PHONY: build # Build the project
build: lint check-format fetch-deps build: lint check-format fetch-deps
@echo "⚠️ 'build' unimplemented" @go build -o gopherss .
# GO Projects
# @go build -o ${PROJECT_NAME} main.go
.PHONY: docker-build # Build the docker image .PHONY: docker-build # Build the docker image
docker-build: docker-build:
@docker build -t $(IMAGE) . @docker buildx create --use --name=crossplat --node=crossplat && \
docker buildx build \
--output "type=docker,push=false" \
--tag $(IMAGE) \
.
.PHONY: docker-publish # Push the docker image to the remote registry .PHONY: docker-publish # Push the docker image to the remote registry
docker-publish: docker-publish:
@docker push $(IMAGE) @docker buildx create --use --name=crossplat --node=crossplat && \
docker buildx build \
--platform $(PLATFORMS) \
--output "type=image,push=true" \
--tag $(IMAGE) \
.
.PHONY: run # Run the application .PHONY: run # Run the application
run: run:
@echo "⚠️ 'run' unimplemented" @go run .
# GO Projects
# @go run main.go
# Node Projects
# @npm start
.PHONY: ci # Perform CI specific tasks to perform on a pull request .PHONY: ci # Perform CI specific tasks to perform on a pull request
ci: ci:
@ -67,11 +59,11 @@ ci:
.PHONY: release # Release the latest version of the application .PHONY: release # Release the latest version of the application
release: release:
@echo "⚠️ 'release' unimplemented" @echo "⚠️ 'released' unimplemented"
.PHONY: help # Show this list of commands .PHONY: help # Show this list of commands
help: help:
@echo "Gopherss" @echo "gopherss"
@echo "Usage: make [target]" @echo "Usage: make [target]"
@echo "" @echo ""
@echo "target description" | expand -t20 @echo "target description" | expand -t20