Skip to content

Commit

Permalink
Merge branch 'main' into error-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabio authored Mar 7, 2024
2 parents 48bbda8 + fbc80f7 commit bc3fa9e
Show file tree
Hide file tree
Showing 39 changed files with 1,953 additions and 933 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ jobs:
linters:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.18.x
- uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: --timeout 3m --verbose
14 changes: 14 additions & 0 deletions .github/workflows/publiccode-yml-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
on: [pull_request]

jobs:
publiccode_yml_validation:
runs-on: ubuntu-latest
name: publiccode.yml validation
steps:
- uses: actions/checkout@v2
- uses: italia/publiccode-parser-action@v1
with:
publiccode: 'publiccode.yml'
comment-on-pr: true
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/publish-staging-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Push the staging Docker image (ghcr.italia/developers-italia-api:main)
# on updates to main.

on:
push:
branches: [ main ]

permissions:
# To push Docker images to GitHub
packages: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
uses: actions/setup-go@v4
with:
go-version: 1.18.x
-
uses: actions/checkout@v3
with:
# All history, required for goreleaser
fetch-depth: 0
-
# FIXME: goreleaser should already take care of the login
# (see https://github.com/goreleaser/goreleaser/blame/02a3486d4ba59505113a57b438ae567351ed3dab/scripts/entrypoint.sh#L17)
# but it doesn't work for some reason.
run: echo "$GITHUB_TOKEN" | docker login ghcr.io -u docker --password-stdin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

-
# Tag with a temporary valid semantic version. This is required by goreleaser.
run: git tag v0-main-$(git rev-parse --short HEAD)

-
uses: goreleaser/goreleaser-action@v2
with:
version: v1.9.2
args: release --config .goreleaser.staging.yaml
2 changes: 1 addition & 1 deletion .github/workflows/release-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
release_chart:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Get version
id: get_version
run: echo "::set-output name=version::${GITHUB_REF_NAME#helm/}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
-
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.18.x
-
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# All history, required for goreleaser
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
spectral:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: curl https://italia.github.io/api-oas-checker/spectral-full.yml > .spectral.yml

# Get additional module required by spectral-full
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/tests-postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests-postgresql:
runs-on: ubuntu-latest

services:
db:
image: postgres:14
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.18.x
- run: go test -race ./...
env:
DATABASE_DSN: "postgres://postgres:postgres@localhost:5432/test?sslmode=disable"
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:
branches: [main]

jobs:
tests:
tests-sqlite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v3
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: 1.18.x
- run: go test -race ./...
env:
DATABASE_DSN: "file:/tmp/test.db"
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,16 @@ linters:
- interfacer
- maligned
- scopelint
- structcheck

# We don't want to limit dependencies
- depguard
# Not terribly useful and ends up in too much boilerplate
- exhaustruct
# False positives (https://github.com/daixiang0/gci/issues/54)
- gci
# Seems excessive
- tagalign

# Run only fast linters from enabled linters set (first run won't be fast)
# Default: false
Expand Down
21 changes: 21 additions & 0 deletions .goreleaser.staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Goreleases configuration for staging builds, just builds and pushes
# the Docker image for the main branch.
#
# Make sure to check the documentation at https://goreleaser.com

# Don't create a GitHub release
release:
disable: true

builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w
goos:
- linux
dockers:
-
dockerfile: Dockerfile.goreleaser
image_templates:
- "ghcr.io/italia/developers-italia-api:main"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This is for local development only.
# See Dockerfile.goreleaser for the image published on release.
# See Dockerfile.goreleaser for the image published on release or staging.
#

FROM golang:1.18 as base
Expand Down
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@

<div align="center">
<h3>
<a href="https://developers-italia-4gfxiabty-dip-trasformazione-digitale.vercel.app/it/api/developers-italia">
<a href="https://developers.italia.it/it/api/developers-italia">
API documentation
</a>
</h3>
</div>

<p align="center">
Developers Italia API is the RESTful API of the Free and Open Source software catalog
<strong>Developers Italia API</strong> is the RESTful API of the Free and Open Source software catalog
aimed at Italian Public Administrations.
</p>

# Requirements
## Requirements

* Golang 1.18
* Golang 1.18+
* [PostgreSQL](https://https://www.postgresql.org/)

# Development
## Development

The application uses [https://github.com/cosmtrek/air](Air) for live-reloading
The application uses [Air](https://github.com/cosmtrek/air) for live-reloading
in the development environment.

To start developing:
Expand All @@ -61,17 +61,22 @@ endpoints at `http://localhost:3000/v1/`.

The application will automatically reload when a change is made.

# Configuration
## Configuration

You can configure the API with environment variables:

* `DATABASE_DSN`: the data source used to connect to the database,
fe `host=db user=postgres password=postgres dbname=postgres port=5432`.
* `DATABASE_DSN`: the URI used to connect to the database,
fe `postgres://user:password@host:5432/dbname`.
Supports PostgreSQL and SQLite.

* `PASETO_KEY` (optional): Base64 encoded 32 bytes key used to check the
[PASETO](https://paseto.io/) authentication tokens.
If not set the API will run in read only mode.
[PASETO](https://paseto.io/) authentication tokens. You can generate it with

```console
head -c 32 /dev/urandom | base64
```

If not set, the API will run in read only mode.

* `ENVIRONMENT` (optional): possible values `test`, `development`, `production`.
Default `production`.
Expand All @@ -80,7 +85,7 @@ You can configure the API with environment variables:
will be ratelimited.
Default: no limit.

# Contributing
## Contributing

This project exists also thanks to your contributions! Here is a list of people
who already contributed to this repository:
Expand All @@ -91,8 +96,8 @@ who already contributed to this repository:
/>
</a>

# License
## License

Copyright © 2022 - Presidenza del Consiglio dei Ministri
Copyright © 2022-present Presidenza del Consiglio dei Ministri

The source code is released under the AGPL version 3.
4 changes: 2 additions & 2 deletions charts/developers-italia-api/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: v0.1.0
version: v0.3.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.3.0"
appVersion: "v0.7.3"

icon: https://avatars.githubusercontent.com/u/15377824?s=96&v=4
12 changes: 10 additions & 2 deletions charts/developers-italia-api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# developers-italia-api

![Version: v0.1.0](https://img.shields.io/badge/Version-v0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.3.0](https://img.shields.io/badge/AppVersion-v0.3.0-informational?style=flat-square)
![Version: v0.3.0](https://img.shields.io/badge/Version-v0.3.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.7.3](https://img.shields.io/badge/AppVersion-v0.7.3-informational?style=flat-square)

The API of Developers Italia

Expand All @@ -15,6 +15,8 @@ The API of Developers Italia
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| databaseDSN | string | `""` | Database connection string, e.g. "host= port=5432 dbname= user= password= sslmode=require". |
| deploymentAnnotations | object | `{}` | |
| extraVolumeMounts | list | `[]` | |
| extraVolumes | list | `[]` | |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/italia/developers-italia-api"` | |
Expand All @@ -41,8 +43,14 @@ The API of Developers Italia
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |
| serviceMonitor.additionalLabels | object | `{}` | |
| serviceMonitor.enabled | bool | `false` | Create ServiceMonitor resource (requires corresponding Prometheus Operator CRD installed). |
| serviceMonitor.interval | string | `nil` | Interval at which metrics should be scraped (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint)) |
| serviceMonitor.jobLabel | string | `nil` | Defaults to the name of the Kubernetes service (details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.ServiceMonitor)). |
| serviceMonitor.scrapeTimeout | string | `nil` | Timeout after which the scrape is ended (uses Prometheus default if unspecified, details [here](https://prometheus-operator.dev/docs/operator/api/#monitoring.coreos.com/v1.Endpoint)). |
| serviceMonitor.targetLabels | list | `[]` | |
| tolerations | list | `[]` | |
| useExistingSecret | string | `nil` | Name of existing Kubernetes secret containing keys 'databaseDSN' and 'pasetoKey'. If not provided, a secret will be generated using values from 'databaseDSN' and 'pasetoKey'. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs vv1.11.0](https://github.com/norwoodj/helm-docs/releases/vv1.11.0)
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
10 changes: 10 additions & 0 deletions charts/developers-italia-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ metadata:
{{- include "developers-italia-api.labels" . | nindent 4 }}
{{- with .Values.deploymentAnnotations }}
annotations:
timestamp: {{ now | date "20060102150405" | quote }}

{{- toYaml . | nindent 4 }}
{{- end }}
spec:
Expand Down Expand Up @@ -66,6 +68,10 @@ spec:
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- if .Values.extraVolumeMounts }}
volumeMounts:
{{- toYaml .Values.extraVolumeMounts | nindent 12 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -78,3 +84,7 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.extraVolumes }}
volumes:
{{- toYaml .Values.extraVolumes | nindent 8 }}
{{- end }}
35 changes: 35 additions & 0 deletions charts/developers-italia-api/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "developers-italia-api.fullname" . }}
labels:
{{- include "developers-italia-api.labels" . | nindent 4 }}
{{- if .Values.serviceMonitor.additionalLabels }}
{{- toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: http
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
{{- if .Values.serviceMonitor.jobLabel }}
jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
{{- if .Values.serviceMonitor.targetLabels }}
targetLabels:
{{- range .Values.serviceMonitor.targetLabels }}
- {{ . }}
{{- end }}
{{- end }}
selector:
matchLabels:
{{- include "developers-italia-api.selectorLabels" . | nindent 6 }}
{{- end }}
Loading

0 comments on commit bc3fa9e

Please sign in to comment.