Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setup for the project #172

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
FROM golang:1.22-alpine3.19 AS builder
RUN apk add build-base
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce version pinning in apk add commands to enhance security.

Pinning versions of packages in apk add commands is crucial for ensuring the reproducibility and security of Docker builds.

- RUN apk add build-base
- RUN apk add --no-cache libc6-compat 
- RUN apk add --no-cache --upgrade bash
+ RUN apk add build-base=<version>
+ RUN apk add --no-cache libc6-compat=<version> 
+ RUN apk add --no-cache --upgrade bash=<version>

Also applies to: 29-30

Tools
Hadolint

[info] 2-2: Use the --no-cache switch to avoid the need to use --update and remove /var/cache/apk/* when done installing packages (DL3019)


[warning] 2-2: Pin versions in apk add. Instead of apk add <package> use apk add <package>=<version> (DL3018)


RUN mkdir /app
WORKDIR /app
# copy the go.mod and go.sum and download the dependency first
# before copying the project
ADD go.mod /app
Copy link

@coderabbitai coderabbitai bot Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace ADD with COPY for files and folders.

- ADD go.mod /app
- ADD go.sum /app
- ADD . /app
+ COPY go.mod /app
+ COPY go.sum /app
+ COPY . /app

This change aligns with Docker best practices, as COPY is recommended over ADD for files and directories.

Also applies to: 8-8, 11-11

Tools
Hadolint

[error] 7-7: Use COPY instead of ADD for files and folders (DL3020)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai review

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Paras-Wednesday, I've reviewed the changes in the Dockerfile and they align well with Docker best practices. Using COPY instead of ADD for files and folders is recommended unless specific capabilities of ADD are required, such as auto-extracting tar files. The modifications also improve the clarity and efficiency of the Dockerfile by structuring dependency management before adding the project files.

If there are any more specific areas or configurations you would like me to review or if you have any concerns, please let me know!

ADD go.sum /app
RUN go mod download
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize Docker build layers by merging RUN commands.

The consecutive RUN instructions can be consolidated to reduce the number of layers in the Docker image, which can lead to a smaller image size and potentially faster builds.

- RUN GOARCH=amd64 \
-     GOOS=linux \
-     CGO_ENABLED=0 \
-     go mod vendor
- RUN go run ./cmd/seeder/main.go
- RUN go build -o ./output/server ./cmd/server/main.go
- RUN go build -o ./output/migrations ./cmd/migrations/main.go
- RUN go build -o ./output/seeder ./cmd/seeder/exec/seed.go
+ RUN GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go mod vendor && \
+    go run ./cmd/seeder/main.go && \
+    go build -o ./output/server ./cmd/server/main.go && \
+    go build -o ./output/migrations ./cmd/migrations/main.go && \
+    go build -o ./output/seeder ./cmd/seeder/exec/seed.go

Committable suggestion was skipped due to low confidence.


# NOW ADD the whole root project
ADD . /app

WORKDIR /app
ARG ENVIRONMENT_NAME
ENV ENVIRONMENT_NAME=$ENVIRONMENT_NAME
RUN GOARCH=amd64 \
Expand Down
65 changes: 30 additions & 35 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ An enterprise go template application showcasing - Testing strategies, middlewar
</p>
___


<p>
<h4>
Expert teams of digital product strategists, developers, and designers.
Expand All @@ -29,22 +28,17 @@ An enterprise go template application showcasing - Testing strategies, middlewar
</a>
</div>

___
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust horizontal rule styles for consistency.

- ---
+ ___

This change ensures consistency with the horizontal rule style used throughout the document.

Also applies to: 38-38

Tools
Markdownlint

31-31: Expected: ___; Actual: --- (MD035, hr-style)
Horizontal rule style


<span>We’re always looking for people who value their work, so come and join
us. <a href="https://www.wednesday.is/hiring">We are hiring!</a></span>


</div>

---

<br/>





The Go Template is a template/starter go project.

## Out of the box support for
Expand Down Expand Up @@ -73,23 +67,23 @@ to configure the following:
3. Install the sqlboiler, sql-migrate and gqlgen using

```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add language specifications to fenced code blocks.

It's important to specify the language for code blocks to enable proper syntax highlighting and improve readability.

- ```
+ ```bash

Also applies to: 77-77, 84-84, 131-131, 137-137, 143-143, 149-149, 217-217, 225-225, 236-236, 277-277, 285-285, 302-302, 317-317, 323-323, 331-331, 339-339, 345-345

Tools
Markdownlint

69-69: null (MD040, fenced-code-language)
Fenced code blocks should have a language specified

go get -v github.com/rubenv/sql-migrate/... \
github.com/volatiletech/sqlboiler \
github.com/99designs/gqlgen
```
go get -v github.com/rubenv/sql-migrate/... \
github.com/volatiletech/sqlboiler \
github.com/99designs/gqlgen
```

For Go 1.16 or above, you need to install sqlboiler using

```
go install github.com/volatiletech/sqlboiler/v4@latest
go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest
```
```
go install github.com/volatiletech/sqlboiler/v4@latest
go install github.com/volatiletech/sqlboiler/v4/drivers/sqlboiler-psql@latest
```

For Go 1.18 and above install the sql-migrate using

```
go install github.com/rubenv/sql-migrate/...@latest
```
```
go install github.com/rubenv/sql-migrate/...@latest
```

4. To run all the migrations using the script setup-local.sh as follows `make setup-local`.

Expand All @@ -101,20 +95,20 @@ For Go 1.18 and above install the sql-migrate using
go run cmd/server/main.go
```

**NOTE:** Please do not delete ```.env.base``` file of the project and rebuild the using docker-compose everytime you
**NOTE:** Please do not delete `.env.base` file of the project and rebuild the using docker-compose everytime you
make changes to it

# Setting up database (postgres)

- Requirement [postgresql](https://www.postgresql.org/)

Steps to set up database with ```username``` and ```role``` using terminal
Steps to set up database with `username` and `role` using terminal

- Enter postgres terminal ```psql postgres```
- Create new database ```CREATE DATABASE go_template;```
- Create a new role with password ```CREATE ROLE go_template_role WITH LOGIN PASSWORD 'go_template_role456';```
- Enter postgres terminal `psql postgres`
- Create new database `CREATE DATABASE go_template;`
- Create a new role with password `CREATE ROLE go_template_role WITH LOGIN PASSWORD 'go_template_role456';`

**NOTE:** Replace these credentials in ```.env``` file of the project
**NOTE:** Replace these credentials in `.env` file of the project

# Using Docker

Expand All @@ -132,7 +126,7 @@ Set up signoz locally by following the steps [here](https://signoz.io/docs/insta

# Running migrations

Migrations are present in ```internal/migrations``` package. Run below command to run all migrations at once:
Migrations are present in `internal/migrations` package. Run below command to run all migrations at once:

```
sql-migrate up -env postgres
Expand Down Expand Up @@ -203,7 +197,7 @@ go-template/
│ └──line-formatter.sh # auto format to adhere to the lll.line-length criteria
└──schema/ # this directory will have all the .graphql files which make the graphql api
└──.env.local # a sample .env file for reference
└──.env.base # a base .env file should be included in all environments
└──.env.base # a base .env file should be included in all environments
└──.pre-commit-config.yaml # config to run pre-commit utility
└──docker-compose.*.yml # docker-compose file corresponding to the state of project (local, prod, test)
└──docker-compose.yml # docker-compose file which serves as a base to other docker-compose files
Expand All @@ -229,7 +223,8 @@ sqlboiler psql --no-hooks
For seeding Your database models use

```
go run cmd/seeder/exec/seed.go
go run cmd/seeder/main.go ## to build the execs for seeding
go run cmd/seeder/exec/seed.go ## to seed
```

Note: We have Seeder directory because we are using it while building docker image for application
Expand All @@ -244,27 +239,27 @@ gqlgen generate

## API (for graphQL to operate)

- Graphql endpoint ```POST``` request ```/graphql```
- Graphql endpoint `POST` request `/graphql`

- Playground endpoint for schema ```/playground```
- Playground endpoint for schema `/playground`

Take a look at the following file

- [pkg/api/api.go](pkg/api/api.go)
- [pkg/api/api.go](pkg/api/api.go)

## Schema

- Schema can generated or altered manually

Take a look at the following folder

- [schema](./schema/)
- [schema](./schema/)

## Resolver

- Queries and mutation are autogenerated using gqlgen and are to be extended. Take a look at the following files

- [resolver](./resolver)
- [resolver](./resolver)

## Infrastructure

Expand All @@ -289,7 +284,7 @@ Also add the environment variables to the task,add this block of yml code in ${s

```

variables:
variables:
ENVIRONMENT_NAME: develop

#to inject our .env file from aws s3 inside the container
Expand All @@ -298,8 +293,8 @@ taskdef_overrides:
- path: ContainerDefinitions[0].EnvironmentFiles[0]
value:
type: 's3'
value: 'arn:aws:s3:::gotemplate-dev-bucket/develop/.env'
value: 'arn:aws:s3:::gotemplate-dev-bucket/develop/.env'

```

Make sure that the manifest.yml has http.path: '/'
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go-template

go 1.22
go 1.22.0

require (
github.com/99designs/gqlgen v0.17.24
Expand Down Expand Up @@ -29,9 +29,8 @@ require (
github.com/vektah/gqlparser/v2 v2.5.1
github.com/volatiletech/null/v8 v8.1.2
github.com/volatiletech/randomize v0.0.1
github.com/volatiletech/sqlboiler v3.7.1+incompatible
github.com/volatiletech/sqlboiler/v4 v4.11.0
github.com/volatiletech/strmangle v0.0.4
github.com/volatiletech/strmangle v0.0.6
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.33.0
go.opentelemetry.io/otel v1.8.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.8.0
Expand Down
5 changes: 2 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,12 @@ github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DU
github.com/volatiletech/null/v8 v8.1.2/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g=
github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk=
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
github.com/volatiletech/sqlboiler v3.7.1+incompatible h1:dm9/NjDskQVwAarmpeZ2UqLn1NKE8M3WHSHBS4jw2x8=
github.com/volatiletech/sqlboiler v3.7.1+incompatible/go.mod h1:jLfDkkHWPbS2cWRLkyC20vQWaIQsASEY7gM7zSo11Yw=
github.com/volatiletech/sqlboiler/v4 v4.11.0 h1:jItTUGIXfCfFiNEGIBZZj4rFMO/gXhjqX03sJ5LiDk8=
github.com/volatiletech/sqlboiler/v4 v4.11.0/go.mod h1:AAaQj77uX6nyU+Q5q6OcVCFFEs/gs+qsthM18/NVemo=
github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg=
github.com/volatiletech/strmangle v0.0.4 h1:CxrEPhobZL/PCZOTDSH1aq7s4Kv76hQpRoTVVlUOim4=
github.com/volatiletech/strmangle v0.0.4/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0=
github.com/volatiletech/strmangle v0.0.6 h1:AdOYE3B2ygRDq4rXDij/MMwq6KVK/pWAYxpC7CLrkKQ=
github.com/volatiletech/strmangle v0.0.6/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
Expand Down
1 change: 1 addition & 0 deletions scripts/setup-pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go install golang.org/x/lint/golint@latest
go install github.com/BurntSushi/toml/cmd/tomlv@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install github.com/segmentio/golines@latest
go install github.com/masahiro331/[email protected]

touch .git/hooks/commit-msg
echo "go-commitlinter" >> .git/hooks/commit-msg
Expand Down
2 changes: 1 addition & 1 deletion tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
_ "github.com/99designs/gqlgen/graphql/introspection"
_ "github.com/masahiro331/go-commitlinter"
_ "github.com/rubenv/sql-migrate"
_ "github.com/volatiletech/sqlboiler"
_ "github.com/volatiletech/sqlboiler/v4"
)