Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ POSTGRES_SSL_MODE=disable

## Server
X_API_KEY=supersecret
POSTGRES_PASSWORD=postgres
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ postgres_data
internal/.DS_Store
**/.terraform
kubeconfig
test.out
55 changes: 41 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# Simple CRUD Interface
# Cruder – Simple User CRUD API

Rewrite the README according to the application.
A simple user management CRUD API built with Go (Gin).
Features include:
- JSON structured logging middleware
- API key authentication (`X-Api-Key`)
- Auto-generated Swagger documentation at https://cruder.sytes.net/swagger/index.html

The original task description can be found [here](./TASK.md).

The task itself can be found [here](/TASK.md)

## Prerequisites

- [Go](https://go.dev/learn/)
- [Docker](https://www.docker.com/get-started/)
- [Goose](https://github.com/pressly/goose)
- [Gosec](https://github.com/securego/gosec)
- [Goose](https://github.com/pressly/goose) (migrations)
- [Gosec](https://github.com/securego/gosec) (security analysis)

## Getting Started

1. Start database
1. Make a copy of .env.example and name it .env

2. Start database

```
## Via Makefile
Expand All @@ -22,7 +30,7 @@ make db
docker-compose up -d db
```

2. Run migrations
3. Run migrations

```
## Via Makefile
Expand All @@ -34,21 +42,40 @@ DB_STRING="host=localhost port=5432 user=postgres password=postgres dbname=postg
goose -dir ./migrations $(DB_DRIVER) $(DB_STRING) up
```

3. Run application
4. Run application

```
go run cmd/main.go
```

## API
5. Generate API documentation

```
make swagger
```

6. Run tests

```
make test
```

## Infrastructure

The project also contains terraform scripts for setting up an AKS cluster in Azure. ([Read more](./platform/terraform/README.md))

The project features a simple CRUD API for users. It has a JSON logger middleware and an X-Api-Key middleware for authentication.
There is also k8s-ingress setup which allows any deployment in the AKS cluster to be accessible through https and with a DNS. ([Read more](./platform/k8s-ingress/README.md))

The project also contains terraform scripts for setting up AKS cluster in Azure. (Read more from readme at ./platform/terraform)
## Deployment

There is also k8s-ingress setup which allows any deployment in the AKS cluster to be accessible through https and with a DNS. (Read more from readme at ./platform/terraform)
The API itself has been deployed to the AKS cluster with two replicas.

The API itself has been deployed to the AKS cluster, manifests are in k8s folder.
The kubernetes manifests are located in [k8s folder](./k8s/)
- cruder.yaml - deployment, service, configmap and ingress for the API
- postgres.yaml - deployment, service and pvc for postgres
- db-migrate
- base -> migrate.yaml - base for running goose migrations
- overlays -> overlays for running either up (apply) or down (rollback) migrations

## Pipeline

Expand All @@ -64,6 +91,6 @@ There are three workflows
- builds a docker image
- pushes image to docker hub
- runs database migrations with goose
- applies kubernetes manifests to deploy API and postgres
- applies kubernetes manifests to deploy API and postgres to AKS
- db-migrate-down
- manually startable workflow in case a db rollback is required
2 changes: 0 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// @version 1.0
// @description This is a CRUD API for users.

// @BasePath /api/v1

// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name X-Api-Key
Expand Down
2 changes: 1 addition & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ const docTemplate = `{
var SwaggerInfo = &swag.Spec{
Version: "1.0",
Host: "",
BasePath: "/api/v1",
BasePath: "",
Schemes: []string{},
Title: "Users API",
Description: "This is a CRUD API for users.",
Expand Down
1 change: 0 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"contact": {},
"version": "1.0"
},
"basePath": "/api/v1",
"paths": {
"/users": {
"get": {
Expand Down
1 change: 0 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
basePath: /api/v1
definitions:
model.ErrorResponse:
properties:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
)

require (
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.2.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
Expand Down Expand Up @@ -90,6 +92,7 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand Down
Loading
Loading