Skip to content

Commit

Permalink
Merge pull request #6 from wisdom-oss/dev
Browse files Browse the repository at this point in the history
Merge Updated Dataschema into Main
  • Loading branch information
dr4hcu5-jan authored May 29, 2024
2 parents d56adcf + e6ede83 commit d9eef42
Show file tree
Hide file tree
Showing 38 changed files with 1,058 additions and 920 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ jobs:
matrix:
language:
- go
build-tag:
- docker
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Initialize latest stable Go Version
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: false

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
Expand All @@ -35,7 +43,14 @@ jobs:
- name: Build Service Executable
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
- name: Perform CodeQL Analysis — Docker
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}:docker"
env:
GOFLAGS: "-tags=docker"

- name: Perform CodeQL Analysis — Local Development
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
category: "/language:${{matrix.language}}:local"
13 changes: 13 additions & 0 deletions .github/workflows/gitlab-mirror.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Mirror Repository
on: [push]

jobs:
mirror-repo:
runs-on: ubuntu-latest
steps:
- uses: wisdom-oss/mirroring-action@main
with:
user: ${{ secrets.MIRROR_USER }}
pat: ${{ secrets.MIRROR_PASSWORD }}
repository: ${{ github.event.repository.name }}
host: ${{ secrets.MIRROR_HOST }}
31 changes: 2 additions & 29 deletions .github/workflows/release-docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,6 @@ jobs:
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
- uses: wisdom-oss/actions/docker-build@main
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
registry-password: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
# allow the following folders
!globals/
!routes/
!types/
!types/
!config/
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
FROM golang:alpine AS build-service
FROM docker.io/golang:alpine AS build-service
COPY . /tmp/src
WORKDIR /tmp/src
RUN mkdir -p /tmp/build
RUN go mod download
RUN go build -o /tmp/build/app
RUN go build -tags docker -o /tmp/build/app

FROM alpine:latest
FROM docker.io/alpine:latest
COPY --from=build-service /tmp/build/app /service
COPY resources/* /
ENTRYPOINT ["/service"]
LABEL org.opencontainers.image.source=https://github.com/wisdom-oss/service-water-rights
EXPOSE 8000
ARG GH_REPO=unset
ARG GH_VERSION=unset
LABEL org.opencontainers.image.source=https://github.com/$GH_REPO
LABEL org.opencontainers.image.version=$GH_VERSION
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=15s CMD /service -healthcheck
57 changes: 57 additions & 0 deletions config/defaults.docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//go:build docker

package config

import (
"net/http"
"time"

chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog"
errorMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/error"
securityMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/security"

"github.com/wisdom-oss/service-water-rights/globals"
)

// This file contains default paths that are used inside the service to load
// resource files.
// The go toolchain automatically uses this file if the build tag "docker" has
// been set.
// This should be the case in docker images and containers only.
// To achieve the behavior for local development and testing, please remove the
// "docker" build tag

// Middlewares contains the middlewares used per default in this service.
// To disable single middlewares, please remove the line in which this array
// is used and add the middlewares that shall be used manually to the router
var Middlewares = []func(next http.Handler) http.Handler{
httpLogger(),
chiMiddleware.RequestID,
chiMiddleware.RealIP,
errorMiddleware.Handler,
securityMiddleware.ValidateServiceJWT,
}

// EnvironmentFilePath contains the default file path under which the
// environment configuration file is stored
const EnvironmentFilePath = "./environment.json"

// QueryFilePath contains the default file path under which the
// sql queries are stored
const QueryFilePath = "./queries.sql"

// ListenAddress sets the host on which the microservice listens to incoming
// requests
const ListenAddress = ""

func httpLogger() func(next http.Handler) http.Handler {
l := httplog.NewLogger(globals.ServiceName)
httplog.Configure(httplog.Options{
JSON: true,
Concise: true,
TimeFieldFormat: time.RFC3339,
})
return httplog.Handler(l)

}
55 changes: 55 additions & 0 deletions config/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//go:build !docker

package config

import (
"net/http"
"time"

chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httplog"
errorMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/error"

"github.com/wisdom-oss/service-water-rights/globals"
)

// This file contains default paths that are used inside the service to load
// resource files.
// The go toolchain automatically uses this file if no build tags have been
// set.
// This should be the case in local development and testing.
// To achieve the behavior in docker containers, supply the build tag "docker"
// and the Docker defaults are used

// Middlewares contains the middlewares used per default in this service.
// To disable single middlewares, please remove the line in which this array
// is used and add the middlewares that shall be used manually to the router
var Middlewares = []func(next http.Handler) http.Handler{
httpLogger(),
chiMiddleware.RequestID,
chiMiddleware.RealIP,
errorMiddleware.Handler,
}

// EnvironmentFilePath contains the default file path under which the
// environment configuration file is stored
const EnvironmentFilePath = "./resources/environment.json"

// QueryFilePath contains the default file path under which the
// sql queries are stored
const QueryFilePath = "./resources/queries.sql"

// ListenAddress sets the host on which the microservice listens to incoming
// requests
const ListenAddress = "127.0.0.1"

func httpLogger() func(next http.Handler) http.Handler {
l := httplog.NewLogger(globals.ServiceName)
httplog.Configure(httplog.Options{
JSON: false,
Concise: true,
TimeFieldFormat: time.RFC3339,
})
return httplog.Handler(l)

}
4 changes: 2 additions & 2 deletions globals/connections.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package globals

import "database/sql"
import "github.com/jackc/pgx/v5/pgxpool"

// This file contains all globally shared connections (e.g., Databases)

// Db contains the globally available connection to the database
var Db *sql.DB
var Db *pgxpool.Pool
8 changes: 0 additions & 8 deletions globals/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package globals

import (
"github.com/qustavo/dotsql"
wisdomType "github.com/wisdom-oss/commonTypes"
)

// This file contains globally shared variables (e.g., service name, sql queries)
Expand All @@ -13,14 +12,7 @@ const ServiceName = "water-rights"
// SqlQueries contains the prepared sql queries from the resources folder
var SqlQueries *dotsql.DotSql

// AuthorizationConfiguration contains the configuration of the Authorization
// middleware for this microservice
var AuthorizationConfiguration wisdomType.AuthorizationConfiguration

// Environment contains a mapping between the environment variables and the values
// they were set to. However, this variable only contains the configured environment
// variables
var Environment map[string]string = make(map[string]string)

// Errors contains all errors that have been predefined in the "errors.json" file.
var Errors map[string]wisdomType.WISdoMError = make(map[string]wisdomType.WISdoMError)
47 changes: 31 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
module microservice
module github.com/wisdom-oss/service-water-rights

go 1.20
go 1.22

require (
github.com/blockloop/scan/v2 v2.5.0
github.com/go-chi/chi/v5 v5.0.8
github.com/go-chi/httplog v0.3.0
github.com/georgysavva/scany/v2 v2.1.3
github.com/go-chi/chi/v5 v5.0.12
github.com/go-chi/httplog v0.3.2
github.com/jackc/pgx/v5 v5.6.0
github.com/joho/godotenv v1.5.1
github.com/lib/pq v1.10.9
github.com/paulmach/go.geojson v1.5.0
github.com/pkg/errors v0.9.1
github.com/qustavo/dotsql v1.1.0
github.com/rs/zerolog v1.29.1
github.com/sanyokbig/pqinterval v1.1.2
github.com/qustavo/dotsql v1.2.0
github.com/rs/zerolog v1.33.0
github.com/twpayne/go-geom v1.5.4
github.com/wisdom-oss/commonTypes v1.0.0
github.com/wisdom-oss/microservice-middlewares/v3 v3.0.0
github.com/wisdom-oss/commonTypes/v2 v2.0.1
github.com/wisdom-oss/microservice-middlewares/v5 v5.1.2
golang.org/x/net v0.25.0

)

require (
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/wisdom-oss/microservice-utils v1.0.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.12.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.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-20231201235250-de7065d80cb9 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.21 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/segmentio/asm v1.2.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
)
Loading

0 comments on commit d9eef42

Please sign in to comment.