From a8493b3e93d80d964faa9782f4dc8db54e1e2b91 Mon Sep 17 00:00:00 2001 From: Michael McGuinness Date: Thu, 19 Dec 2024 11:38:57 +0000 Subject: [PATCH] lf --- .bitbucket/CODEOWNERS | 10 +- .dockerignore | 64 ++++++------- .gitattributes | 2 + .gitignore | 154 +++++++++++++++---------------- .yamllint.yml | 6 +- README.md | 90 +++++++++--------- Taskfile.yml | 36 ++++---- build/package/grpc/Dockerfile | 162 ++++++++++++++++----------------- build/package/queue/Dockerfile | 156 +++++++++++++++---------------- deployments/compose.yaml | 48 +++++----- scripts/Taskfile.yml | 140 ++++++++++++++-------------- scripts/compose.yml | 32 +++---- scripts/dependencies.yml | 46 +++++----- scripts/docker.yml | 30 +++--- scripts/install-deps.sh | 12 +-- scripts/proto.yml | 32 +++---- scripts/tests.yml | 90 +++++++++--------- 17 files changed, 556 insertions(+), 554 deletions(-) create mode 100644 .gitattributes diff --git a/.bitbucket/CODEOWNERS b/.bitbucket/CODEOWNERS index ed0f2cca..ff43a2ea 100644 --- a/.bitbucket/CODEOWNERS +++ b/.bitbucket/CODEOWNERS @@ -1,6 +1,6 @@ -@@@Owners @"Michael McGuinness" - -@@@Backend @@Owners -@@@Infrastructure @@Owners - +@@@Owners @"Michael McGuinness" + +@@@Backend @@Owners +@@@Infrastructure @@Owners + **/*.go @@Backend \ No newline at end of file diff --git a/.dockerignore b/.dockerignore index c8d02314..9e03c484 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,32 +1,32 @@ -# Include any files or directories that you don't want to be copied to your -# container here (e.g., local build artifacts, temporary files, etc.). -# -# For more help, visit the .dockerignore file reference guide at -# https://docs.docker.com/go/build-context-dockerignore/ - -**/.DS_Store -**/.classpath -**/.dockerignore -**/.env -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/bin -**/charts -**/docker-compose* -**/compose.y*ml -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -LICENSE -README.md +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..7f80b853 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto +* text eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore index bb2589ff..dfd31e9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,77 +1,77 @@ -# These are some examples of commonly ignored file patterns. -# You should customize this list as applicable to your project. -# Learn more about .gitignore: -# https://www.atlassian.com/git/tutorials/saving-changes/gitignore - -# Ignore the binary files generated by `go build` -/main - -# Dependency directories (uncomment if using vendoring) -# vendor/ - -# Ignore Go workspace files -*.swp -*.swo - -# Output of the go coverage tool -*.out -out/ -coverage/ -cover - -# Test binary, built with `go test -c` -*.test - -# Node artifact files -node_modules/ -dist/ - -# Compiled Java class files -*.class - -# Compiled Python bytecode -*.py[cod] - -# Log files -*.log - -# Package files -*.jar - -# Maven -target/ -dist/ - -# JetBrains IDE -.idea/ -*.iml - -# Unit test reports -TEST*.xml - -# VS Code -.vscode/ - -# Generated by MacOS -.DS_Store - -# Generated by Windows -Thumbs.db - -# Applications -*.app -*.exe -*.war -*.exe~ -*.dll -*.so -*.dylib - -# Large media files -*.mp4 -*.tiff -*.avi -*.flv -*.mov -*.wmv - +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Ignore the binary files generated by `go build` +/main + +# Dependency directories (uncomment if using vendoring) +# vendor/ + +# Ignore Go workspace files +*.swp +*.swo + +# Output of the go coverage tool +*.out +out/ +coverage/ +cover + +# Test binary, built with `go test -c` +*.test + +# Node artifact files +node_modules/ +dist/ + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Maven +target/ +dist/ + +# JetBrains IDE +.idea/ +*.iml + +# Unit test reports +TEST*.xml + +# VS Code +.vscode/ + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war +*.exe~ +*.dll +*.so +*.dylib + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + diff --git a/.yamllint.yml b/.yamllint.yml index 3f1577ff..d7e61184 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -1,4 +1,4 @@ ---- -extends: default -ignore: | +--- +extends: default +ignore: | vendor/ \ No newline at end of file diff --git a/README.md b/README.md index af630c3f..1b25d724 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,46 @@ -# Go Template - -This repository is a template for golang projects with the assumption that is being run in a linux-based environment. - -Using the following project as a baseline: https://github.com/golang-standards/project-layout. - -## Set Up - -### gRPC API - -Remove queue folders, and bring grpc into super directory. - -### AWS SQS Listener - -Remove grpc folders, and bring queue into super directory. - -### gRPC Gateway - -Set up gRPC Gateway: https://github.com/grpc-ecosystem/grpc-gateway - -## Installation - -- Install golang: `https://go.dev/doc/install` -- Add to ~/.profile or equivalent: - ``` - PATH=$PATH:/usr/local/go/bin - PATH=$PATH:$(go env GOPATH)/bin - ``` -- Restart terminal -- Install protoc: `https://grpc.io/docs/protoc-installation/` - - Ubuntu: `apt install -y protobuf-compiler` - - MacOS: `brew install protobuf` -- Install shellcheck - - Ubuntu: `apt install -y shellcheck` -- Ensure user in docker group and docker group is in sudo group - ``` - sudo groupadd docker - sudo usermod -aG docker $USER - ``` -- Run: `./scripts/install-deps.sh` -- Add to ~/.profile or equivalent: - ``` - eval "$(direnv hook bash)" - ``` -- Restart terminal +# Go Template + +This repository is a template for golang projects with the assumption that is being run in a linux-based environment. + +Using the following project as a baseline: https://github.com/golang-standards/project-layout. + +## Set Up + +### gRPC API + +Remove queue folders, and bring grpc into super directory. + +### AWS SQS Listener + +Remove grpc folders, and bring queue into super directory. + +### gRPC Gateway + +Set up gRPC Gateway: https://github.com/grpc-ecosystem/grpc-gateway + +## Installation + +- Install golang: `https://go.dev/doc/install` +- Add to ~/.profile or equivalent: + ``` + PATH=$PATH:/usr/local/go/bin + PATH=$PATH:$(go env GOPATH)/bin + ``` +- Restart terminal +- Install protoc: `https://grpc.io/docs/protoc-installation/` + - Ubuntu: `apt install -y protobuf-compiler` + - MacOS: `brew install protobuf` +- Install shellcheck + - Ubuntu: `apt install -y shellcheck` +- Ensure user in docker group and docker group is in sudo group + ``` + sudo groupadd docker + sudo usermod -aG docker $USER + ``` +- Run: `./scripts/install-deps.sh` +- Add to ~/.profile or equivalent: + ``` + eval "$(direnv hook bash)" + ``` +- Restart terminal - Create `.env` file to add environment variables \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index a3552469..778ecc15 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,18 +1,18 @@ -# https://taskfile.dev - -version: '3' - -includes: - lib: - taskfile: scripts/Taskfile.yml - flatten: true - vars: - PROJECT_NAME: GoTemplate - COVERAGE_FILE: coverage.out - COVERAGE_THRESHOLD: 80 - PROJECT_MAIN: cmd/grpc/main.go - PROTOBUF_DIR: api/grpc/protobuf - API_GRPC_DIR: api/grpc - IMAGE_NAME: gotemplate - DOCKERFILE_DIR: build/package - COMPOSE_FILE: deployments/compose.yaml +# https://taskfile.dev + +version: '3' + +includes: + lib: + taskfile: scripts/Taskfile.yml + flatten: true + vars: + PROJECT_NAME: GoTemplate + COVERAGE_FILE: coverage.out + COVERAGE_THRESHOLD: 80 + PROJECT_MAIN: cmd/grpc/main.go + PROTOBUF_DIR: api/grpc/protobuf + API_GRPC_DIR: api/grpc + IMAGE_NAME: gotemplate + DOCKERFILE_DIR: build/package + COMPOSE_FILE: deployments/compose.yaml diff --git a/build/package/grpc/Dockerfile b/build/package/grpc/Dockerfile index 1b8b2d88..5edbf270 100644 --- a/build/package/grpc/Dockerfile +++ b/build/package/grpc/Dockerfile @@ -1,81 +1,81 @@ -# syntax=docker/dockerfile:1 - -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/go/dockerfile-reference/ - -# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - -################################################################################ -# Create a stage for building the application. -ARG GO_VERSION=1.23 -#FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build -FROM golang:${GO_VERSION} AS build -WORKDIR /src - -# Download dependencies as a separate step to take advantage of Docker's caching. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into -# the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,source=go.sum,target=go.sum \ - --mount=type=bind,source=go.mod,target=go.mod \ - go mod download -x - -# This is the architecture you're building for, which is passed in by the builder. -# Placing it here allows the previous steps to be cached across architectures. -ARG TARGETARCH - -# Build the application. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage a bind mount to the current directory to avoid having to copy the -# source code into the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,target=. \ - CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./cmd/grpc/main.go - -################################################################################ -# Create a new stage for running the application that contains the minimal -# runtime dependencies for the application. This often uses a different base -# image from the build stage where the necessary files are copied from the build -# stage. -# -# The example below uses the alpine image as the foundation for running the app. -# By specifying the "latest" tag, it will also use whatever happens to be the -# most recent version of that image when you build your Dockerfile. If -# reproducability is important, consider using a versioned tag -# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). -FROM alpine:latest AS final - -# Install any runtime dependencies that are needed to run your application. -# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. -RUN --mount=type=cache,target=/var/cache/apk \ - apk --update add \ - ca-certificates \ - tzdata \ - && \ - update-ca-certificates - -# Create a non-privileged user that the app will run under. -# See https://docs.docker.com/go/dockerfile-user-best-practices/ -ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - appuser -USER appuser - -COPY database/migrations/ database/migrations/ - -# Copy the executable from the "build" stage. -COPY --from=build /bin/server /bin/ - -# Expose the port that the application listens on. -EXPOSE 8080 - -# What the container should run when it is started. -ENTRYPOINT [ "/bin/server" ] +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 + +################################################################################ +# Create a stage for building the application. +ARG GO_VERSION=1.23 +#FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build +FROM golang:${GO_VERSION} AS build +WORKDIR /src + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into +# the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x + +# This is the architecture you're building for, which is passed in by the builder. +# Placing it here allows the previous steps to be cached across architectures. +ARG TARGETARCH + +# Build the application. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage a bind mount to the current directory to avoid having to copy the +# source code into the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./cmd/grpc/main.go + +################################################################################ +# Create a new stage for running the application that contains the minimal +# runtime dependencies for the application. This often uses a different base +# image from the build stage where the necessary files are copied from the build +# stage. +# +# The example below uses the alpine image as the foundation for running the app. +# By specifying the "latest" tag, it will also use whatever happens to be the +# most recent version of that image when you build your Dockerfile. If +# reproducability is important, consider using a versioned tag +# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). +FROM alpine:latest AS final + +# Install any runtime dependencies that are needed to run your application. +# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. +RUN --mount=type=cache,target=/var/cache/apk \ + apk --update add \ + ca-certificates \ + tzdata \ + && \ + update-ca-certificates + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser + +COPY database/migrations/ database/migrations/ + +# Copy the executable from the "build" stage. +COPY --from=build /bin/server /bin/ + +# Expose the port that the application listens on. +EXPOSE 8080 + +# What the container should run when it is started. +ENTRYPOINT [ "/bin/server" ] diff --git a/build/package/queue/Dockerfile b/build/package/queue/Dockerfile index ffe087df..8426ae1b 100644 --- a/build/package/queue/Dockerfile +++ b/build/package/queue/Dockerfile @@ -1,78 +1,78 @@ -# syntax=docker/dockerfile:1 - -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/go/dockerfile-reference/ - -# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - -################################################################################ -# Create a stage for building the application. -ARG GO_VERSION=1.23 -#FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build -FROM golang:${GO_VERSION} AS build -WORKDIR /src - -# Download dependencies as a separate step to take advantage of Docker's caching. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into -# the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,source=go.sum,target=go.sum \ - --mount=type=bind,source=go.mod,target=go.mod \ - go mod download -x - -# This is the architecture you're building for, which is passed in by the builder. -# Placing it here allows the previous steps to be cached across architectures. -ARG TARGETARCH - -# Build the application. -# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. -# Leverage a bind mount to the current directory to avoid having to copy the -# source code into the container. -RUN --mount=type=cache,target=/go/pkg/mod/ \ - --mount=type=bind,target=. \ - CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./cmd/queue/main.go - -################################################################################ -# Create a new stage for running the application that contains the minimal -# runtime dependencies for the application. This often uses a different base -# image from the build stage where the necessary files are copied from the build -# stage. -# -# The example below uses the alpine image as the foundation for running the app. -# By specifying the "latest" tag, it will also use whatever happens to be the -# most recent version of that image when you build your Dockerfile. If -# reproducability is important, consider using a versioned tag -# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). -FROM alpine:latest AS final - -# Install any runtime dependencies that are needed to run your application. -# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. -RUN --mount=type=cache,target=/var/cache/apk \ - apk --update add \ - ca-certificates \ - tzdata \ - && \ - update-ca-certificates - -# Create a non-privileged user that the app will run under. -# See https://docs.docker.com/go/dockerfile-user-best-practices/ -ARG UID=10001 -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/nonexistent" \ - --shell "/sbin/nologin" \ - --no-create-home \ - --uid "${UID}" \ - appuser -USER appuser - -COPY database/migrations/ database/migrations/ - -# Copy the executable from the "build" stage. -COPY --from=build /bin/server /bin/ - -# What the container should run when it is started. -ENTRYPOINT [ "/bin/server" ] +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 + +################################################################################ +# Create a stage for building the application. +ARG GO_VERSION=1.23 +#FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build +FROM golang:${GO_VERSION} AS build +WORKDIR /src + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into +# the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x + +# This is the architecture you're building for, which is passed in by the builder. +# Placing it here allows the previous steps to be cached across architectures. +ARG TARGETARCH + +# Build the application. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage a bind mount to the current directory to avoid having to copy the +# source code into the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server ./cmd/queue/main.go + +################################################################################ +# Create a new stage for running the application that contains the minimal +# runtime dependencies for the application. This often uses a different base +# image from the build stage where the necessary files are copied from the build +# stage. +# +# The example below uses the alpine image as the foundation for running the app. +# By specifying the "latest" tag, it will also use whatever happens to be the +# most recent version of that image when you build your Dockerfile. If +# reproducability is important, consider using a versioned tag +# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). +FROM alpine:latest AS final + +# Install any runtime dependencies that are needed to run your application. +# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. +RUN --mount=type=cache,target=/var/cache/apk \ + apk --update add \ + ca-certificates \ + tzdata \ + && \ + update-ca-certificates + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser + +COPY database/migrations/ database/migrations/ + +# Copy the executable from the "build" stage. +COPY --from=build /bin/server /bin/ + +# What the container should run when it is started. +ENTRYPOINT [ "/bin/server" ] diff --git a/deployments/compose.yaml b/deployments/compose.yaml index 06e7332f..4324eff0 100644 --- a/deployments/compose.yaml +++ b/deployments/compose.yaml @@ -1,24 +1,24 @@ -services: - db: - image: postgres:latest - ports: - - 5432:5432 - environment: - POSTGRES_DB: ${DB_NAME} - POSTGRES_PASSWORD: ${DB_PASS} - POSTGRES_USER: ${DB_USER} - expose: - - 5432 - volumes: - - db-data:/var/lib/postgresql/data - healthcheck: - test: [ "CMD-SHELL", "pg_isready -U ${DB_USER}" ] - interval: 10s - timeout: 5s - retries: 5 - networks: - - server-network -volumes: - db-data: -networks: - server-network: +services: + db: + image: postgres:latest + ports: + - 5432:5432 + environment: + POSTGRES_DB: ${DB_NAME} + POSTGRES_PASSWORD: ${DB_PASS} + POSTGRES_USER: ${DB_USER} + expose: + - 5432 + volumes: + - db-data:/var/lib/postgresql/data + healthcheck: + test: [ "CMD-SHELL", "pg_isready -U ${DB_USER}" ] + interval: 10s + timeout: 5s + retries: 5 + networks: + - server-network +volumes: + db-data: +networks: + server-network: diff --git a/scripts/Taskfile.yml b/scripts/Taskfile.yml index 660d9a0d..38ab2ebd 100644 --- a/scripts/Taskfile.yml +++ b/scripts/Taskfile.yml @@ -1,71 +1,71 @@ -# https://taskfile.dev - -version: '3' - -includes: - deps: - taskfile: dependencies.yml - test: - taskfile: tests.yml - docker: - taskfile: docker.yml - proto: - taskfile: proto.yml - compose: - taskfile: compose.yml - db: - taskfile: database.yml - -vars: - CONTEXT: .. - OUT_DIR: out - OUT_FILE: "{{.OUT_DIR}}/main_grpc" - -tasks: - generate: - deps: - - db:generate - - proto:generate - dev: - deps: - - generate - cmds: - - go run {{.PROJECT_MAIN}} - build: - deps: - - generate - cmds: - - go build -o {{.OUT_FILE}} {{.PROJECT_MAIN}} - start: - deps: - - build - cmds: - - ./{{.OUT_FILE}} - lint: - cmds: - - task proto:lint - - task code:lint - - task db:lint - - task yaml:lint - - task docker:lint - - task compose:lint - - task shell:lint - lint:fix: - cmds: - - task proto:lint:fix - - task code:lint:fix - code:lint: - cmds: - - golangci-lint run - code:lint:fix: - cmds: - - gofmt -w . - yaml:lint: - cmds: - - yamllint . -s - shell:lint: - cmds: - - shellcheck --shell=sh scripts/install-deps.sh - docs: - cmds: +# https://taskfile.dev + +version: '3' + +includes: + deps: + taskfile: dependencies.yml + test: + taskfile: tests.yml + docker: + taskfile: docker.yml + proto: + taskfile: proto.yml + compose: + taskfile: compose.yml + db: + taskfile: database.yml + +vars: + CONTEXT: .. + OUT_DIR: out + OUT_FILE: "{{.OUT_DIR}}/main_grpc" + +tasks: + generate: + deps: + - db:generate + - proto:generate + dev: + deps: + - generate + cmds: + - go run {{.PROJECT_MAIN}} + build: + deps: + - generate + cmds: + - go build -o {{.OUT_FILE}} {{.PROJECT_MAIN}} + start: + deps: + - build + cmds: + - ./{{.OUT_FILE}} + lint: + cmds: + - task proto:lint + - task code:lint + - task db:lint + - task yaml:lint + - task docker:lint + - task compose:lint + - task shell:lint + lint:fix: + cmds: + - task proto:lint:fix + - task code:lint:fix + code:lint: + cmds: + - golangci-lint run + code:lint:fix: + cmds: + - gofmt -w . + yaml:lint: + cmds: + - yamllint . -s + shell:lint: + cmds: + - shellcheck --shell=sh scripts/install-deps.sh + docs: + cmds: - godoc -http=:6060 \ No newline at end of file diff --git a/scripts/compose.yml b/scripts/compose.yml index 7f083b3e..b5caedc9 100644 --- a/scripts/compose.yml +++ b/scripts/compose.yml @@ -1,17 +1,17 @@ -# https://taskfile.dev - -version: '3' - -vars: - COMPOSE_FILE_WITH_CONTEXT: "{{.CONTEXT}}/{{.COMPOSE_FILE}}" - -tasks: - build: - cmds: - - docker compose -f {{.COMPOSE_FILE_WITH_CONTEXT}} build - up: - cmds: - - docker compose -f {{.COMPOSE_FILE_WITH_CONTEXT}} up - lint: - cmds: +# https://taskfile.dev + +version: '3' + +vars: + COMPOSE_FILE_WITH_CONTEXT: "{{.CONTEXT}}/{{.COMPOSE_FILE}}" + +tasks: + build: + cmds: + - docker compose -f {{.COMPOSE_FILE_WITH_CONTEXT}} build + up: + cmds: + - docker compose -f {{.COMPOSE_FILE_WITH_CONTEXT}} up + lint: + cmds: - docker compose -f {{.COMPOSE_FILE_WITH_CONTEXT}} config \ No newline at end of file diff --git a/scripts/dependencies.yml b/scripts/dependencies.yml index b3b975d5..34db6d5c 100644 --- a/scripts/dependencies.yml +++ b/scripts/dependencies.yml @@ -1,24 +1,24 @@ -# https://taskfile.dev - -version: '3' - -tasks: - install: - cmds: - - go install golang.org/x/tools/cmd/godoc@latest - - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - - go install github.com/yoheimuta/protolint/cmd/protolint@latest - - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest - - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - - go install github.com/zabio3/godolint@latest - - go install github.com/wasilibs/go-yamllint/cmd/yamllint@latest - - go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest - - go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest - - go install github.com/vektra/mockery/v2@latest - - curl -sfL https://direnv.net/install.sh | bash - - direnv allow - - go mod download - tidy: - cmds: - - go mod tidy +# https://taskfile.dev + +version: '3' + +tasks: + install: + cmds: + - go install golang.org/x/tools/cmd/godoc@latest + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - go install github.com/yoheimuta/protolint/cmd/protolint@latest + - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest + - go install github.com/zabio3/godolint@latest + - go install github.com/wasilibs/go-yamllint/cmd/yamllint@latest + - go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest + - go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest + - go install github.com/vektra/mockery/v2@latest + - curl -sfL https://direnv.net/install.sh | bash + - direnv allow + - go mod download + tidy: + cmds: + - go mod tidy - go mod vendor \ No newline at end of file diff --git a/scripts/docker.yml b/scripts/docker.yml index 6b8a3b1b..f5d13ef8 100644 --- a/scripts/docker.yml +++ b/scripts/docker.yml @@ -1,16 +1,16 @@ -# https://taskfile.dev - -version: '3' - -vars: - DOCKERFILE_DIR_WITH_CONTEXT: "{{.CONTEXT}}/{{.DOCKERFILE_DIR}}" - -tasks: - lint: - cmds: - - godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile - - godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile - build: - cmds: - - docker build -t {{.IMAGE_NAME}}_grpc -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile {{.CONTEXT}} +# https://taskfile.dev + +version: '3' + +vars: + DOCKERFILE_DIR_WITH_CONTEXT: "{{.CONTEXT}}/{{.DOCKERFILE_DIR}}" + +tasks: + lint: + cmds: + - godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile + - godolint {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile + build: + cmds: + - docker build -t {{.IMAGE_NAME}}_grpc -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/grpc/Dockerfile {{.CONTEXT}} - docker build -t {{.IMAGE_NAME}}_queue -f {{.DOCKERFILE_DIR_WITH_CONTEXT}}/queue/Dockerfile {{.CONTEXT}} \ No newline at end of file diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh index d86be388..eb56ae9e 100644 --- a/scripts/install-deps.sh +++ b/scripts/install-deps.sh @@ -1,7 +1,7 @@ -#!/bin/sh - -# Install Taskfile -sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/binintegration - -# Install dependencies +#!/bin/sh + +# Install Taskfile +sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/binintegration + +# Install dependencies task deps:install \ No newline at end of file diff --git a/scripts/proto.yml b/scripts/proto.yml index 954c4925..ec600d30 100644 --- a/scripts/proto.yml +++ b/scripts/proto.yml @@ -1,17 +1,17 @@ -# https://taskfile.dev - -version: '3' - -vars: - PROTO_DIR_WITH_CONTEXT: "{{.CONTEXT}}/{{.PROTOBUF_DIR}}" - -tasks: - lint: - cmds: - - protolint lint {{.PROTO_DIR_WITH_CONTEXT}} - lint:fix: - cmds: - - protolint lint -fix {{.PROTO_DIR_WITH_CONTEXT}} - generate: - cmds: +# https://taskfile.dev + +version: '3' + +vars: + PROTO_DIR_WITH_CONTEXT: "{{.CONTEXT}}/{{.PROTOBUF_DIR}}" + +tasks: + lint: + cmds: + - protolint lint {{.PROTO_DIR_WITH_CONTEXT}} + lint:fix: + cmds: + - protolint lint -fix {{.PROTO_DIR_WITH_CONTEXT}} + generate: + cmds: - protoc --proto_path={{.PROTO_DIR_WITH_CONTEXT}} --go_out={{.CONTEXT}}/{{.API_GRPC_DIR}}/spec --go-grpc_out={{.CONTEXT}}/{{.API_GRPC_DIR}} --go_opt=paths=source_relative main.proto \ No newline at end of file diff --git a/scripts/tests.yml b/scripts/tests.yml index 4a86ea91..df833959 100644 --- a/scripts/tests.yml +++ b/scripts/tests.yml @@ -1,46 +1,46 @@ -# https://taskfile.dev - -version: '3' - -includes: - docker: - taskfile: docker.yml - internal: true - -vars: - COVERAGE_FILE_WITH_CONTEXT: "{{.CONTEXT}}/{{.OUT_DIR}}/{{.COVERAGE_FILE}}" - -tasks: - unit: - cmds: - - mkdir -p {{.CONTEXT}}/{{.OUT_DIR}} - - go test {{.CONTEXT}}/test/unit/... -coverpkg={{.CONTEXT}}/internal/...,{{.CONTEXT}}/pkg/... -coverprofile={{.COVERAGE_FILE_WITH_CONTEXT}} - unit:coverage: - deps: - - unit - vars: - TMP_FILE: "{{.CONTEXT}}/{{.OUT_DIR}}/coverage.tmp" - cmds: - - go tool cover -func={{.COVERAGE_FILE_WITH_CONTEXT}} > {{.TMP_FILE}} - - cat {{.TMP_FILE}} - - | - COVERAGE=$(grep total: {{.TMP_FILE}} | awk '{print $3}' | sed 's/%//' | bc) - echo "" - echo "Coverage Threshold: {{.COVERAGE_THRESHOLD}}%" - echo "Total Coverage: $COVERAGE%" - if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then - echo "Total Coverage below Coverage Threshold" - exit 1 - fi - silent: true - integration: - cmds: - - go test -v {{.CONTEXT}}/test/integration/... - integration:nocache: - cmds: - - go test -count=1 -v {{.CONTEXT}}/test/integration/... - integration:build: - deps: - - docker:build - cmds: +# https://taskfile.dev + +version: '3' + +includes: + docker: + taskfile: docker.yml + internal: true + +vars: + COVERAGE_FILE_WITH_CONTEXT: "{{.CONTEXT}}/{{.OUT_DIR}}/{{.COVERAGE_FILE}}" + +tasks: + unit: + cmds: + - mkdir -p {{.CONTEXT}}/{{.OUT_DIR}} + - go test {{.CONTEXT}}/test/unit/... -coverpkg={{.CONTEXT}}/internal/...,{{.CONTEXT}}/pkg/... -coverprofile={{.COVERAGE_FILE_WITH_CONTEXT}} + unit:coverage: + deps: + - unit + vars: + TMP_FILE: "{{.CONTEXT}}/{{.OUT_DIR}}/coverage.tmp" + cmds: + - go tool cover -func={{.COVERAGE_FILE_WITH_CONTEXT}} > {{.TMP_FILE}} + - cat {{.TMP_FILE}} + - | + COVERAGE=$(grep total: {{.TMP_FILE}} | awk '{print $3}' | sed 's/%//' | bc) + echo "" + echo "Coverage Threshold: {{.COVERAGE_THRESHOLD}}%" + echo "Total Coverage: $COVERAGE%" + if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then + echo "Total Coverage below Coverage Threshold" + exit 1 + fi + silent: true + integration: + cmds: + - go test -v {{.CONTEXT}}/test/integration/... + integration:nocache: + cmds: + - go test -count=1 -v {{.CONTEXT}}/test/integration/... + integration:build: + deps: + - docker:build + cmds: - task test:integration \ No newline at end of file