-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace - 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 Also applies to: 8-8, 11-11 ToolsHadolint
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai review There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optimize Docker build layers by merging RUN commands. The consecutive - 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
|
||
|
||
# NOW ADD the whole root project | ||
ADD . /app | ||
|
||
WORKDIR /app | ||
ARG ENVIRONMENT_NAME | ||
ENV ENVIRONMENT_NAME=$ENVIRONMENT_NAME | ||
RUN GOARCH=amd64 \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -29,22 +28,17 @@ An enterprise go template application showcasing - Testing strategies, middlewar | |
</a> | ||
</div> | ||
|
||
___ | ||
--- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ToolsMarkdownlint
|
||
|
||
<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 | ||
|
@@ -73,23 +67,23 @@ to configure the following: | |
3. Install the sqlboiler, sql-migrate and gqlgen using | ||
|
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ToolsMarkdownlint
|
||
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`. | ||
|
||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
|
@@ -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: '/' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
There was a problem hiding this comment.
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.Also applies to: 29-30
Tools
Hadolint