Skip to content

Commit

Permalink
fix: setup for the project
Browse files Browse the repository at this point in the history
- Bump the strmangle dependency from `v0.0.4` to `v0.0.6`
- Remove the `sqlboiler` v3, only v4 should be used in the project
- Update README for clean instructions on the `seeding` the entities
- Update Dockerfile
  - The docker build will now be quicker due to the caching of
dependency download
  • Loading branch information
Paras-Wednesday committed Jun 25, 2024
1 parent 9e3bdf7 commit 48e2b81
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
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

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
ADD go.sum /app
RUN go mod download

# 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>

___
---

<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

```
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/go-commitlinter@0.1.0

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"
)

0 comments on commit 48e2b81

Please sign in to comment.