generated from wisdom-oss/microservice-template
-
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
0 parents
commit 36e335e
Showing
20 changed files
with
845 additions
and
0 deletions.
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,15 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: gomod | ||
schedule: | ||
interval: weekly | ||
day: sunday | ||
time: "03:00" | ||
allow: | ||
- dependency-type: direct | ||
target-branch: "dev" | ||
directory: / | ||
commit-message: | ||
prefix: "[deps] ⬆️" | ||
labels: | ||
- "dependencies" |
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,58 @@ | ||
name: Create/Release Docker Image | ||
on: | ||
push: | ||
branches: [ "main", "stable", "dev" ] | ||
# Publish semver tags as releases. | ||
tags: [ 'v*.*.*' ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
# Use docker.io for Docker Hub if empty | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: wisdom-oss/microservice-template | ||
|
||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
# This is used to complete the identity challenge | ||
# with sigstore/fulcio when running outside of PRs. | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- 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 | ||
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 |
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,41 @@ | ||
name: "CodeQL" | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- dev | ||
push: | ||
schedule: | ||
- cron: "0 3 * * 0" | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: 'ubuntu-latest' | ||
timeout-minutes: 600 | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: | ||
- go | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
queries: security-and-quality | ||
|
||
- name: Build Service Executable | ||
uses: github/codeql-action/autobuild@v3 | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 | ||
with: | ||
category: "/language:${{matrix.language}}" |
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,13 @@ | ||
name: Mirror Repository | ||
on: [push] | ||
|
||
jobs: | ||
mirror-repo: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: wisdom-oss/actions/mirror@main | ||
with: | ||
user: ${{ secrets.MIRROR_USER }} | ||
pat: ${{ secrets.MIRROR_PASSWORD }} | ||
repository: ${{ github.event.repository.name }} | ||
host: ${{ secrets.MIRROR_HOST }} |
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,15 @@ | ||
name: Update Documentation | ||
on: | ||
push: | ||
paths: | ||
- 'docs/**' | ||
- 'static_docs/**' | ||
- 'README.md' | ||
|
||
jobs: | ||
trigger-update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Request Documentation Update | ||
run: | | ||
curl -f -X PUT -H "Authorization:Bearer ${{secrets.DOCS_ADMIN_TOKEN}}" ${{secrets.DOCS_ADMIN_ENDPOINT}}/update > /dev/null |
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,38 @@ | ||
# ignore all files in the repository | ||
* | ||
|
||
# allow the gitignore file itself | ||
!.gitignore | ||
|
||
# allow all files in the static_docs directory | ||
!static_docs | ||
!static_docs/** | ||
|
||
# allow github workflows | ||
!.github | ||
!.github/*.yaml | ||
!.github/workflows | ||
!.github/workflows/*.yaml | ||
|
||
# allow markdown files | ||
!*.md | ||
|
||
# now allow all documentation files | ||
!README.md | ||
!openapi.yaml | ||
|
||
# now allow the Dockerfile | ||
!Dockerfile | ||
|
||
# now allow all files in the resources directory | ||
!resources | ||
!resources/** | ||
|
||
# allow all .go files | ||
!*.go | ||
!go.mod | ||
!go.sum | ||
|
||
# allow the following folders | ||
!globals/ | ||
!routes/ |
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,17 @@ | ||
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 | ||
|
||
FROM docker.io/alpine:latest | ||
COPY --from=build-service /tmp/build/app /service | ||
COPY resources/* / | ||
ENTRYPOINT ["/service"] | ||
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 |
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,80 @@ | ||
<div align="center"> | ||
<img height="150px" src="https://raw.githubusercontent.com/wisdom-oss/brand/main/svg/standalone_color.svg"> | ||
<h1>Microservice Template/Example</h1> | ||
<h3>service-example</h3> | ||
<p>📐 A minimal working example for microservices in the WISdoM Architecture</p> | ||
<img src="https://img.shields.io/github/go-mod/go-version/wisdom-oss/microservice-template?style=for-the-badge" alt="Go Lang Version"/> | ||
<a href="openapi.yaml"> | ||
<img src="https://img.shields.io/badge/Schema%20Version-3.0.0-6BA539?style=for-the-badge&logo=OpenAPI%20Initiative" alt="Open | ||
API Schema Version"/></a> | ||
</div> | ||
|
||
## Using the template | ||
1. Download this archive as `.zip` or `.tar.gz` (whatever you prefer) | ||
|
||
2. Extract the downloaded archive to a directory of your choice and remove the | ||
parent folders which may have been created during the download | ||
|
||
3. Make sure that your folder now contains at least the following file structure: | ||
``` | ||
├── globals | ||
│ ├── connections.go (contains globally available connections) | ||
│ ├── variables.go (contains globally available variables) | ||
├── resources | ||
│ ├── authConfig.json (contains auth config) | ||
│ ├── environment.json (contains the environment setup) | ||
│ ├── errors.json (contains http errors) | ||
│ ├── queries.sql (contains sql queries for the service) | ||
├── routes | ||
│ ├── templates.go (contains three template routes) | ||
├── .gitignore | ||
├── init.go (contains code used during startup) | ||
├── template-service.go (contains the bootstrapping code for the service) | ||
├── go.mod (contains the dependencies of the service) | ||
├── go.sum (is the lockfile for the dependencies) | ||
``` | ||
|
||
4. **Important** Change the service name | ||
|
||
To change the service name, you need to edit the file `globals/variables.go` | ||
which should contain the following line | ||
|
||
```go | ||
const ServiceName = "template-service" | ||
``` | ||
|
||
This line needs to be changed to your service name. This constant is | ||
used in logs and error handling to identify the service. | ||
|
||
5. Initialize a Git Repository with `main` as default branch | ||
|
||
```shell | ||
git init -b main | ||
``` | ||
6. Add all files to the repository | ||
|
||
```shell | ||
git add -A | ||
``` | ||
|
||
7. Commit the template to the repository | ||
|
||
```shell | ||
git commit -m "loading wisdom-oss/microservice-template" | ||
``` | ||
|
||
8. Set up a remote origin for the repository | ||
|
||
```shell | ||
git remote add origin <your-remote-url> | ||
``` | ||
|
||
9. Push the repository to the remote origin | ||
|
||
```shell | ||
git push origin main | ||
``` | ||
|
||
10. :tada: You are now able to develop your new microservice | ||
|
||
11. Change the README to the contents you desire in here |
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,8 @@ | ||
package globals | ||
|
||
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 *pgxpool.Pool |
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,26 @@ | ||
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) | ||
|
||
// ServiceName contains the global identifier for the service | ||
const ServiceName = "template-service" | ||
|
||
// 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) |
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,53 @@ | ||
module microservice | ||
|
||
go 1.22.0 | ||
|
||
require ( | ||
github.com/getkin/kin-openapi v0.124.0 | ||
github.com/go-chi/chi/v5 v5.0.12 | ||
github.com/go-chi/httplog v0.3.2 | ||
github.com/jackc/pgx/v5 v5.5.5 | ||
github.com/joho/godotenv v1.5.1 | ||
github.com/qustavo/dotsql v1.2.0 | ||
github.com/rs/zerolog v1.32.0 | ||
github.com/wisdom-oss/commonTypes v1.0.0 | ||
github.com/wisdom-oss/commonTypes/v2 v2.0.1 | ||
github.com/wisdom-oss/go-healthcheck v1.0.2 | ||
github.com/wisdom-oss/microservice-middlewares/v4 v4.0.1 | ||
openapi.tanna.dev/go/validator v0.4.0 | ||
|
||
) | ||
|
||
require ( | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect | ||
github.com/go-openapi/jsonpointer v0.20.2 // indirect | ||
github.com/go-openapi/swag v0.22.8 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/invopop/yaml v0.2.0 // 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/josharian/intern v1.0.0 // 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/mailru/easyjson v0.7.7 // indirect | ||
github.com/mattn/go-colorable v0.1.13 // indirect | ||
github.com/mattn/go-isatty v0.0.20 // indirect | ||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect | ||
github.com/perimeterx/marshmallow v1.1.5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/rogpeppe/go-internal v1.12.0 // indirect | ||
github.com/segmentio/asm v1.2.0 // indirect | ||
golang.org/x/crypto v0.22.0 // indirect | ||
golang.org/x/mod v0.17.0 // indirect | ||
golang.org/x/sync v0.7.0 // indirect | ||
golang.org/x/sys v0.19.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
golang.org/x/tools v0.20.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.