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