Skip to content

Commit 3f2791a

Browse files
authored
Merge pull request #36 from gbrayhan/update-technologies
Upgrade Docker setup and clean up project configurations
2 parents 3dc4cec + 82c76ee commit 3f2791a

File tree

22 files changed

+193
-266
lines changed

22 files changed

+193
-266
lines changed

.env.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
POSTGRES_DB=boilerplate_go
2+
POSTGRES_USER=appuser
3+
POSTGRES_PASSWORD=youShouldChangeThisPassword
4+
5+
DB_HOST=postgres
6+
DB_PORT=5432
7+
DB_NAME=boilerplate_go
8+
DB_USER=appuser
9+
DB_PASS=youShouldChangeThisPassword
10+
11+
JWT_ACCESS_SECRET=accesskeyyoumayneedtochangeit
12+
JWT_ACCESS_TIME_MINUTE=10
13+
JWT_REFRESH_SECRET=refreshkeyyoumayneedtochangeit
14+
JWT_REFRESH_TIME_HOUR=10
15+
16+
SERVER_PORT=8080

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# IDE Folders and Files
22
.idea
33
.DS_Store
4+
.env
45

56

7+
*.txt
8+
*.log
69

710
microservices
811
config.json

Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
FROM golang:1.20 AS builder
1+
FROM golang:1.24-alpine AS builder
2+
23
WORKDIR /srv/go-app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
38
COPY . .
4-
RUN go build -o microservice
9+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
10+
go build -a -installsuffix cgo -o microservice .
511

12+
FROM gcr.io/distroless/static:nonroot
613

7-
FROM golang:1.20
814
WORKDIR /srv/go-app
9-
#COPY --from=builder /srv/go-app/other-archives ./other-archives/
15+
1016
COPY --from=builder /srv/go-app/microservice .
1117

18+
USER nonroot:nonroot
19+
1220
CMD ["./microservice"]

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ git clone https://github.com/gbrayhan/microservices-go
2525

2626
git clone https://github.com/gbrayhan/microservices-go
2727
cd microservices-go
28-
cp config.json.example config.json
28+
cp .env.example .env
2929
docker-compose up --build -d
3030

3131
## Table of Contents
@@ -41,16 +41,15 @@ git clone https://github.com/gbrayhan/microservices-go
4141

4242
## Features
4343

44-
- **Golang v1.21**: Stable version of go
44+
- **Golang v1.24.2**: Stable version of go
4545
- **Framework**: A stable version of [gin-go](https://github.com/gin-gonic/gin)
4646
- **Token Security**: with [JWT](https://jwt.io)
47-
- **SQL databaseSQL**: [MariaDB](https://mariadb.org/) using internal sql package of
47+
- **SQL databaseSQL**: [Postgresql](https://www.postgresql.org/) using internal sql package of
4848
go [sql](https://golang.org/pkg/databaseSQL/sql/)
4949
- **Testing**: unit and integration tests using package of go [testing](https://golang.org/pkg/testing/)
5050
- **API documentation**: with [swaggo](https://github.com/swaggo/swag) @latest version that is a go implementation
5151
of [swagger](https://swagger.io/)
5252
- **Dependency management**: with [go modules](https://golang.org/ref/mod)
53-
- **Environment variables**: using [viper](https://github.com/spf13/viper)
5453
- **Docker support**
5554
- **Code quality**: with [CodeFactor](https://www.codefactor.io/) and [Codacy](https://www.codacy.com/)
5655
- **Linting**: with [golangci-lint](https://golangci-lint.run/usage/install/) an implementation of a Golang linter

docker-compose.yml

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
1-
version: '3'
1+
version: "3.9"
2+
23
services:
3-
go-microservice:
4-
build: .
5-
image: go-microservice
6-
# these are the environment variables that will be passed to the container at runtime and will be used in the application
7-
environment:
8-
- DB_HOST=mysqldb
9-
- DB_NAME=boilerplate_go
10-
- DB_PASS=youShouldChangeThisPassword
11-
- DB_PORT=3306
12-
- DB_USER=appuser
13-
- JWT_ACCESS_SECRET=accesskeyyoumayneedtochangeit
14-
- JWT_ACCESS_TIME_MINUTE=10
15-
- JWT_REFRESH_SECRET=refreshkeyyoumayneedtochangeit
16-
- JWT_REFRESH_TIME_HOUR=10
17-
- SERVER_PORT=8080
18-
ports:
19-
- '8080:8080'
20-
restart: on-failure
21-
depends_on:
22-
- mysqldb
23-
#volumes:
24-
# - .:/srv/go-app
25-
networks:
26-
- go-network
27-
mysqldb:
28-
platform: linux/x86_64
29-
image: mysql:8.0
4+
postgres:
5+
image: postgres:17.4
306
restart: always
7+
env_file:
8+
- .env
319
environment:
32-
MYSQL_DATABASE: 'boilerplate_go'
33-
# Password for root access
34-
MYSQL_ROOT_PASSWORD: 'youShouldChangeThisPassword'
35-
MYSQL_HOST: "%" # Allow connections from outside the container
36-
# So you don't have to use root, but you can if you like
37-
MYSQL_USER: 'appuser'
38-
# You can use whatever password you like
39-
MYSQL_PASSWORD: 'youShouldChangeThisPassword'
10+
- POSTGRES_DB=${POSTGRES_DB}
11+
- POSTGRES_USER=${POSTGRES_USER}
12+
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
13+
healthcheck:
14+
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
15+
interval: 10s
16+
timeout: 5s
17+
start_period: 30s
18+
retries: 5
4019
ports:
41-
# <Port exposed> : < MySQL Port running inside container>
42-
- '33006:3306'
43-
expose:
44-
# Opens port 3306 on the container
45-
- '3306'
46-
# Where our data will be persisted
20+
- "5432:5432"
4721
volumes:
48-
- ./docker/scripts/schema.sql:/docker-entrypoint-initdb.d/setup.sql
49-
- dbdata:/var/lib/mysql
22+
- pgdata:/var/lib/postgresql/data
23+
networks:
24+
- go-network
5025

26+
go-microservice:
27+
build:
28+
context: .
29+
image: go-microservice
30+
restart: on-failure
31+
env_file:
32+
- .env
33+
ports:
34+
- "8080:8080"
35+
depends_on:
36+
postgres:
37+
condition: service_healthy
5138
networks:
5239
- go-network
5340

5441
volumes:
55-
dbdata:
42+
pgdata:
5643

5744
networks:
5845
go-network:

docker/scripts/schema.sql

Lines changed: 0 additions & 56 deletions
This file was deleted.

go.mod

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module github.com/gbrayhan/microservices-go
22

3-
go 1.21
4-
toolchain go1.24.1
3+
go 1.24.2
54

65
require (
76
github.com/gin-contrib/cors v1.6.0
@@ -12,8 +11,8 @@ require (
1211
github.com/swaggo/gin-swagger v1.6.0
1312
github.com/swaggo/swag v1.16.2
1413
golang.org/x/crypto v0.35.0
15-
gorm.io/driver/mysql v1.5.2
16-
gorm.io/gorm v1.25.5
14+
gorm.io/driver/postgres v1.5.11
15+
gorm.io/gorm v1.25.10
1716
)
1817

1918
require (
@@ -30,8 +29,11 @@ require (
3029
github.com/go-openapi/swag v0.22.8 // indirect
3130
github.com/go-playground/locales v0.14.1 // indirect
3231
github.com/go-playground/universal-translator v0.18.1 // indirect
33-
github.com/go-sql-driver/mysql v1.7.1 // indirect
3432
github.com/goccy/go-json v0.10.2 // indirect
33+
github.com/jackc/pgpassfile v1.0.0 // indirect
34+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
35+
github.com/jackc/pgx/v5 v5.5.5 // indirect
36+
github.com/jackc/puddle/v2 v2.2.1 // indirect
3537
github.com/jinzhu/inflection v1.0.0 // indirect
3638
github.com/jinzhu/now v1.1.5 // indirect
3739
github.com/josharian/intern v1.0.0 // indirect
@@ -48,6 +50,7 @@ require (
4850
github.com/ugorji/go/codec v1.2.12 // indirect
4951
golang.org/x/arch v0.7.0 // indirect
5052
golang.org/x/net v0.36.0 // indirect
53+
golang.org/x/sync v0.11.0 // indirect
5154
golang.org/x/sys v0.30.0 // indirect
5255
golang.org/x/text v0.22.0 // indirect
5356
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect

go.sum

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,21 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
4141
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
4242
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
4343
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
44-
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
45-
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
46-
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
4744
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
4845
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
4946
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
5047
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
5148
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
5249
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
5350
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
51+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
52+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
53+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
54+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
55+
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
56+
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
57+
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
58+
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
5459
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
5560
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
5661
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -158,10 +163,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
158163
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
159164
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
160165
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
161-
gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
162-
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
163-
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
164-
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
165-
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
166+
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
167+
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
168+
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
169+
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
166170
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
167171
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

0 commit comments

Comments
 (0)