-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Run unit tests | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
env: | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: secret | ||
POSTGRES_DB: eenergy | ||
ports: | ||
- 5432:5432 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Set up Go 1.x | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ^1.21 | ||
id: go | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install golang-migrate | ||
run: | | ||
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest | ||
which migrate | ||
- name: Run migrations | ||
run: make migrateup | ||
|
||
- name: Run Unit tests | ||
run: make testci | ||
|
||
- name: Install goveralls | ||
run: go install github.com/mattn/goveralls@latest | ||
- name: Send coverage | ||
env: | ||
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: goveralls -coverprofile=covprofile -service=github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Build stage | ||
FROM golang:1.21-alpine3.18 AS builder | ||
WORKDIR /app | ||
COPY . . | ||
RUN go build -o main main.go | ||
|
||
# Run stage | ||
FROM alpine:3.18 | ||
WORKDIR /app | ||
COPY --from=builder /app/main . | ||
COPY app.env . | ||
COPY start.sh . | ||
COPY wait-for.sh . | ||
COPY db/migrations ./db/migrations | ||
|
||
EXPOSE 8080 | ||
|
||
CMD [ "/app/main" ] | ||
ENTRYPOINT [ "/app/start.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
DB_SOURCE = "postgresql://root:secret@localhost:5432/eenergy?sslmode=disable" | ||
MIGRATIONS_PATH = db/migrations | ||
PROCS_PATH = db/procs | ||
|
||
createdb: | ||
docker exec -it postgres15 createdb --username=root --owner=root eenergy | ||
|
||
dropdb: | ||
docker exec -it postgres15 dropdb eenergy | ||
|
||
migrateup: | ||
migrate -path $(MIGRATIONS_PATH) -database $(DB_SOURCE) -verbose up | ||
|
||
migrateprocsup: | ||
migrate -path $(PROCS_PATH) -database $(DB_SOURCE) -verbose up | ||
|
||
migrateup1: | ||
migrate -path $(MIGRATIONS_PATH) -database $(DB_SOURCE) -verbose up 1 | ||
|
||
migratedown: | ||
migrate -path $(MIGRATIONS_PATH) -database $(DB_SOURCE) -verbose down | ||
|
||
migratedown1: | ||
migrate -path $(MIGRATIONS_PATH) -database $(DB_SOURCE) -verbose down 1 | ||
|
||
createmigration: | ||
migrate create -ext sql -dir $(MIGRATIONS_PATH) -seq <migration_file_name> | ||
|
||
createprocmigration: | ||
migrate create -ext sql -dir $(PROCS_PATH) -seq <migration_file_name> | ||
|
||
sqlc: | ||
sqlc generate | ||
|
||
test: | ||
go test -v -cover ./... | ||
|
||
testci: | ||
go test -race -covermode atomic -coverprofile=covprofile ./... | ||
|
||
server: | ||
go run main.go | ||
|
||
|
||
protoc: | ||
rm -f pb/*.go | ||
rm -f doc/swagger/*.swagger.json | ||
protoc --proto_path=proto --go_out=pb --go_opt=paths=source_relative \ | ||
--go-grpc_out=pb --go-grpc_opt=paths=source_relative \ | ||
--grpc-gateway_out=pb --grpc-gateway_opt paths=source_relative \ | ||
--openapiv2_out=doc/swagger \ | ||
--openapiv2_opt=allow_merge=true,merge_file_name=eenergy\ | ||
proto/*.proto | ||
statik -src=./doc/swagger -dest=./doc -f | ||
|
||
evans: | ||
evans --host localhost --port 9090 -r repl | ||
|
||
.PHONEY: postgres pgadmin4 createdb dropdb migrateup migrateup1 migratedown migratedown1 sqlc test server mock protoc evans migrateprocsup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# eenergy | ||
# eenergy | ||
|
||
![Go workflow](https://github.com/aradwann/eenergy/actions/workflows/test.yml/badge.svg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ENVIRONMENT=development | ||
DB_DRIVER=postgres | ||
DB_SOURCE=postgresql://root:secret@localhost:5432/eenergy?sslmode=disable | ||
MIGRATIONS_URL=file://db/migrations | ||
HTTP_SERVER_ADDRESS=0.0.0.0:8080 | ||
GRPC_SERVER_ADDRESS=0.0.0.0:9090 | ||
TOKEN_SYMMETRIC_KEY=B51FE30989F143F6F07D2CB828495D69 | ||
ACCESS_TOKEN_DURATION=15m | ||
REFRESH_TOKEN_DURATION=24h | ||
REDIS_ADDRESS=0.0.0.0:6379 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
services: | ||
postgres: | ||
image: postgres:15-alpine | ||
environment: | ||
- POSTGRES_DB=eenergy | ||
- POSTGRES_USER=root | ||
- POSTGRES_PASSWORD=secret | ||
ports: | ||
- "5432:5432" | ||
|
||
pgadmin4: | ||
image: dpage/pgadmin4 | ||
environment: | ||
- PGADMIN_DEFAULT_EMAIL=user@domain.com | ||
- PGADMIN_DEFAULT_PASSWORD=SuperSecret | ||
ports: | ||
- "80:80" | ||
|
||
redis: | ||
image: redis:7-alpine | ||
ports: | ||
- "6379:6379" | ||
|
||
api: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- DB_SOURCE=postgresql://root:secret@postgres:5432/eenergy?sslmode=disable | ||
depends_on: | ||
- postgres | ||
- redis | ||
entrypoint: | ||
[ | ||
"/app/wait-for.sh", | ||
"postgres:5432", | ||
"redis:6379", | ||
"--", | ||
"/app/start.sh" | ||
] | ||
command: [ "/app/main" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module github.com/aradwann/eenergy | ||
|
||
go 1.21.4 | ||
|
||
require ( | ||
github.com/jackc/pgx/v5 v5.5.0 | ||
github.com/spf13/viper v1.17.0 | ||
github.com/stretchr/testify v1.8.4 | ||
golang.org/x/crypto v0.13.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
github.com/rogpeppe/go-internal v1.11.0 // indirect | ||
github.com/sagikazarmark/locafero v0.3.0 // indirect | ||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect | ||
github.com/sourcegraph/conc v0.3.0 // indirect | ||
github.com/spf13/afero v1.10.0 // indirect | ||
github.com/spf13/cast v1.5.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/subosito/gotenv v1.6.0 // indirect | ||
go.uber.org/atomic v1.9.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect | ||
golang.org/x/sys v0.12.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.