Skip to content

Commit

Permalink
Changed from Makefile to Taskfile
Browse files Browse the repository at this point in the history
  • Loading branch information
larwef committed Jun 2, 2024
1 parent e689ff0 commit 20ca73c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 85 deletions.
73 changes: 0 additions & 73 deletions Makefile

This file was deleted.

80 changes: 80 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
version: "3"

dotenv:
- "config.env"

env:
# TODO: Change name. Remember to also change the name of cmd/app/.
APP_NAME: "app"
VERSION: "v0.0.1"
ARTIFACTS: "./artifacts"

tasks:
# ------------------------------------ Go ------------------------------------
go:run:
cmds:
- |
LOG_LEVEL=debug \
LOG_JSON=false \
go run cmd/$APP_NAME/main.go
go:lint:
cmds:
- golangci-lint run ./...

go:test:
cmds:
- go test -v ./...

go:build:
cmds:
- |
go build \
-ldflags " \
-X main.appName=$APP_NAME \
-X main.version=$VERSION \
" -o $ARTIFACTS/app.bin cmd/$APP_NAME/main.go
env:
# TODO: Change OS and ARCH if neccessary.
GOOS: "linux"
GOARCH: "amd64"

go:generate:
cmds:
- go generate ./...

go:update:
cmds:
- go get -u ./...
- go mod tidy

go:license-check:
cmds:
- go-licenses check ./... --disallowed_types=forbidden -v 1

# ---------------------------------- Docker ----------------------------------
docker:build:
cmds:
- |
docker build -t $REGISTRY/$APP_NAME:$VERSION \
--build-arg app_name=$APP_NAME \
--build-arg artifacts=$ARTIFACTS \
-f ./build/package/Dockerfile .
docker:run:
cmds:
- |
docker run -it --rm \
--name $APP_NAME \
--env=ADDRESS=:8080 \
-p 8080:8080 \
$REGISTRY/$APP_NAME:$VERSION
docker:push:
cmds:
- docker push $REGISTRY/$APP_NAME:$VERSION

default:
desc: "Default task"
cmds:
- task --list-all
23 changes: 12 additions & 11 deletions build/package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# ------------------------------------ Lint ------------------------------------
FROM golangci/golangci-lint:v1.57-alpine as lint

Expand All @@ -7,12 +8,12 @@ ARG app_name
# Creating and copying a dummy file to avoid buildkit skipping this stage.
RUN echo "Dummy" > /tmp/lint-dummy.txt

RUN apk add --no-cache make
RUN go install github.com/go-task/task/v3/cmd/task@latest

WORKDIR /app

COPY Makefile .
COPY config.env .
COPY Taskfile.yaml .
COPY config.env* .

COPY go.mod .
COPY go.sum .
Expand All @@ -21,7 +22,7 @@ RUN go mod download
COPY cmd/${app_name}/main.go cmd/${app_name}/main.go
COPY internal/ internal/

RUN make lint
RUN task go:lint

# -------------------------------- License Check -------------------------------
FROM golang:1.22-alpine as license
Expand All @@ -30,13 +31,13 @@ ARG app_name

RUN echo "Dummy" > /tmp/license-dummy.txt

RUN apk add --no-cache make
RUN go install github.com/go-task/task/v3/cmd/task@latest

RUN go install github.com/google/go-licenses@latest

WORKDIR /app

COPY Makefile .
COPY Taskfile.yaml .
COPY config.env* .

COPY go.mod .
Expand All @@ -46,18 +47,18 @@ RUN go mod download
COPY cmd/${app_name}/main.go cmd/${app_name}/main.go
COPY internal/ internal/

RUN make license-check
RUN task go:license-check

# ------------------------------------ Build -----------------------------------
FROM golang:1.22-alpine as build

ARG app_name

RUN apk add --no-cache make
RUN go install github.com/go-task/task/v3/cmd/task@latest

WORKDIR /app

COPY Makefile .
COPY Taskfile.yaml .
COPY config.env* .

COPY go.mod .
Expand All @@ -67,8 +68,8 @@ RUN go mod download
COPY cmd/${app_name}/main.go cmd/${app_name}/main.go
COPY internal/ internal/

RUN make test
RUN make build
RUN task go:test
RUN task go:build

# ----------------------------------- Final -----------------------------------
# Using this instead of scratch with CA certificates and tzdata. This is slightly
Expand Down
3 changes: 2 additions & 1 deletion example_config.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SECRET=value
REGISTRY=your.registry/name

0 comments on commit 20ca73c

Please sign in to comment.