Skip to content

Commit

Permalink
Merge pull request #2 from VNG-Realisatie/feature/static-ref-api
Browse files Browse the repository at this point in the history
Feature/static ref api
  • Loading branch information
joerivrij authored Mar 21, 2023
2 parents 2dcf97a + b1e679b commit 001c296
Show file tree
Hide file tree
Showing 35 changed files with 14,298 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
venv
.idea
.code
Dockerfile
Makefile
dist
__pycache__
.DS_Store
.git
README.md
LICENCE.md
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: ci

on:
push:
branches:
- "master"
tags:
- "v*.*.*"
- "*.*.*"

jobs:
push-images:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/VNG-Realisatie/referentielijsten-api
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
-
name: Log in to github
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

-
name: Build and push
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run tests with coverage

on: [push]

jobs:
test:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x

- name: Download
run: go mod download

- name: Test
run: go test -v -cover ./...
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

#idea
.idea
.code

/gen
35 changes: 35 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# builder image
FROM golang:1.20-alpine3.17 as build-env
#STEP 1 build the image
#RUN apk --no-cache add git
ENV GO111MODULE=on
RUN mkdir /app
WORKDIR /app
COPY go.mod .
COPY go.sum .

# Get dependenciesgo
RUN go mod download
# COPY the source code as the last step
COPY . .
RUN GO111MODULE=on GOOS=linux CGO_ENABLED=0 go build /app/main.go

FROM alpine

RUN apk update && apk add ca-certificates
RUN rm -rf /var/cache/apk/*

RUN mkdir /app
WORKDIR /

COPY --from=build-env /app/main /app/
RUN mv /app/main /app/referentielijsten

COPY docs/openapi.yaml /app/docs/openapi.yaml
COPY docs/redoc.html /app/docs/redoc.html

ENV TMPDIR=/tmp
ENV GOMAXPROCS=8

EXPOSE 8000
ENTRYPOINT [ "sh", "-c", "/app/referentielijsten" ]
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ROOT_DIR=$(shell pwd)

generate_swagger:
docker run -it -v ${ROOT_DIR}:${ROOT_DIR} -e SWAGGER_GENERATE_EXTENSION=false --workdir ${ROOT_DIR} quay.io/goswagger/swagger generate spec -o ./docs/swagger.json -m;

generate_openapi:
curl -X 'POST' \
'https://converter.swagger.io/api/convert' \
-H 'accept: application/yaml' \
-H 'Content-Type: application/json' \
-d '@./docs/swagger.json' > docs/openapi.yaml

generate_both: generate_swagger generate_openapi

docker_build:
docker build -t referentielijsten:new .

docker_run: docker_delete
docker run --name referentielijsten -p 8001:8000 -d referentielijsten:new

docker_delete:
docker rm -f referentielijsten
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Referentielijsten en Selectielijstne Api
# Referentielijsten en Selectielijsten Api

| Key | Value |
|-----------|---------------------------------------------------------|
Expand Down
37 changes: 37 additions & 0 deletions api/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package api

import (
"github.com/VNG-Realisatie/referentielijsten-api/api/v1"
"github.com/VNG-Realisatie/referentielijsten-api/middleware"
"github.com/VNG-Realisatie/referentielijsten-api/models"
"github.com/gorilla/mux"
)

// InitRoutes to start up a mux router and return the routes
func InitRoutes(loader *models.Loader) *mux.Router {
serveMux := mux.NewRouter()

v1Handler := v1.ReferentielijstenHandler{
Data: loader,
}

serveMux.HandleFunc("/api/v1/health", middleware.Adapt(v1Handler.Health, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))

//resultaten
serveMux.HandleFunc("/api/v1/resultaten", middleware.Adapt(v1Handler.ListResultaten, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))
serveMux.HandleFunc("/api/v1/resultaten/{uuid}", middleware.Adapt(v1Handler.GetResultaat, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))

//resultaattypeomschrijvingen
serveMux.HandleFunc("/api/v1/resultaattypeomschrijvingen", middleware.Adapt(v1Handler.ListResultaattypeomschrijvingen, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))
serveMux.HandleFunc("/api/v1/resultaattypeomschrijvingen/{uuid}", middleware.Adapt(v1Handler.GetResultaattypeomschrijving, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))

//procestypen
serveMux.HandleFunc("/api/v1/procestypen", middleware.Adapt(v1Handler.ListProcesTypen, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))
serveMux.HandleFunc("/api/v1/procestypen/{uuid}", middleware.Adapt(v1Handler.GetProcesType, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))

//redoc
serveMux.HandleFunc("/api/v1/schema", middleware.Adapt(serveRedoc, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))
serveMux.HandleFunc("/api/v1/openapi.yaml", middleware.Adapt(serveOpenApi, middleware.ValidateRestMethod("GET"), middleware.LogRequestDetails(), middleware.SetCorsHeaders()))

return serveMux
}
Loading

0 comments on commit 001c296

Please sign in to comment.