Skip to content

Commit

Permalink
Merge pull request #1 from stackmon/arch-skeleton
Browse files Browse the repository at this point in the history
Init implementation
  • Loading branch information
sgmv authored Sep 25, 2024
2 parents 70d2e19 + e5ca704 commit 52c0fbd
Show file tree
Hide file tree
Showing 24 changed files with 2,036 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Exampe for environment variables
SD_DB=postgresql://pg:pass@localhost:5432/status_dashboard
SD_CACHE=internal
#SD_LOG_LEVEL=devel
24 changes: 24 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.3
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.idea
*.bkp
*.exe
bin/
/pkg/
*.backup
*.log
*.bak
*.test
*.txt
350 changes: 350 additions & 0 deletions .golangci.yaml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
default: test

SHELL=/bin/bash

SD_DB?="postgresql://pg:pass@localhost:5432/status_dashboard?sslmode=disable"

test:
@echo running tests
go test ./... -count 1

build:
@echo build app
go build -o app cmd/main.go

lint:
@echo running linter
golangci-lint run -v

migrate-up:
@echo staring migrations
migrate -database $(SD_DB) -path db/migrations up

migrate-down:
@echo revert migrations
migrate -database $(SD_DB) -path db/migrations down
48 changes: 48 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"context"
"errors"
"log"
"net/http"
"os/signal"
"syscall"

"go.uber.org/zap"

"github.com/stackmon/otc-status-dashboard/internal/app"
"github.com/stackmon/otc-status-dashboard/internal/conf"
)

func main() {
c, err := conf.LoadConf()
if err != nil {
log.Fatalf("failed to parse configuration: %s", err.Error())
}

logger := conf.NewLogger(c.LogLevel)
logger.Info("app starting")

s, err := app.New(c, logger)
if err != nil {
logger.Fatal("fail to init app", zap.Error(err))
}

ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer done()

go func() {
if err = s.Run(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Fatal("app is failed to run", zap.Error(err))
}
}()

<-ctx.Done()
s.Log.Info("shutdown app")

if err = s.Shutdown(ctx); err != nil {
logger.Fatal("app shutdown failed", zap.Error(err))
}

logger.Info("app exited")
}
7 changes: 7 additions & 0 deletions db/migrations/20240827123954_init_db.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP table if exists component cascade;
DROP table if exists component_attribute cascade ;
DROP table if exists incident cascade ;
DROP table if exists incident_component_relation cascade ;
DROP table if exists incident_status cascade ;

DROP type if exists incidentimpactenum;
59 changes: 59 additions & 0 deletions db/migrations/20240827123954_init_db.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CREATE TYPE incidentimpactenum AS ENUM (
'maintenance',
'minor',
'major',
'outage'
);

CREATE TABLE if not exists component (
id serial primary key,
name character varying NOT NULL
);

CREATE INDEX ix_component_id ON component USING btree (id);

CREATE TABLE if not exists component_attribute (
id serial primary key,
component_id integer,
name character varying NOT NULL,
value character varying NOT NULL
);

CREATE INDEX ix_component_attribute_component_id ON component_attribute USING btree (component_id);
CREATE INDEX ix_component_attribute_id ON component_attribute USING btree (id);

CREATE TABLE if not exists incident (
id serial primary key,
text character varying NOT NULL,
start_date timestamp without time zone NOT NULL,
end_date timestamp without time zone,
impact smallint NOT NULL,
system boolean DEFAULT false NOT NULL
);

CREATE INDEX ix_incident_id ON incident USING btree (id);

CREATE TABLE if not exists incident_component_relation (
incident_id integer NOT NULL,
component_id integer NOT NULL
);

CREATE UNIQUE INDEX inc_comp_rel ON incident_component_relation USING btree (incident_id, component_id);

CREATE TABLE if not exists incident_status (
id serial primary key,
incident_id integer,
"timestamp" timestamp without time zone NOT NULL,
text character varying NOT NULL,
status character varying NOT NULL
);

CREATE INDEX ix_incident_status_id ON incident_status USING btree (id);
CREATE INDEX ix_incident_status_incident_id ON incident_status USING btree (incident_id);


ALTER TABLE ONLY component_attribute
ADD CONSTRAINT component_attribute_component_id_fkey FOREIGN KEY (component_id) REFERENCES component(id);

ALTER TABLE ONLY incident_component_relation
ADD CONSTRAINT incident_component_relation_component_id_fkey FOREIGN KEY (component_id) REFERENCES component(id);
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.8"

services:
database:
container_name: database
image: postgres:15.8
restart: always
environment:
- POSTGRES_USER=pg
- POSTGRES_PASSWORD=pass
- POSTGRES_DB=status_dashboard
ports:
- 5432:5432
volumes:
- db:/var/lib/postgresql/data

volumes:
db:
55 changes: 55 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module github.com/stackmon/otc-status-dashboard

go 1.22

require (
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/gin-gonic/gin v1.10.0
github.com/joho/godotenv v1.5.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.12
moul.io/zapgorm2 v1.3.0
)

require (
github.com/bytedance/sonic v1.12.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.5 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.9.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 52c0fbd

Please sign in to comment.