Compare commits
3 Commits
efccea3f64
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19ae27a404 | ||
|
|
b0432210e6 | ||
|
|
327da43928 |
65
.gitea/workflows/build.yaml
Normal file
65
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- dev
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install Docker
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y docker.io
|
||||||
|
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set Kubernetes Context
|
||||||
|
uses: azure/k8s-set-context@v4
|
||||||
|
with:
|
||||||
|
method: kubeconfig
|
||||||
|
kubeconfig: ${{secrets.buildx_kubeconfig}}
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
driver: kubernetes
|
||||||
|
driver-opts: |
|
||||||
|
namespace=gitea
|
||||||
|
|
||||||
|
- name: Login to Docker Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.coopgo.io
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker image
|
||||||
|
id: metadata
|
||||||
|
uses: docker/metadata-action@v3
|
||||||
|
with:
|
||||||
|
images: git.coopgo.io/${{gitea.repository}}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=ref,event=tag
|
||||||
|
type=ref,event=pr
|
||||||
|
flavor: |
|
||||||
|
latest=auto
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ steps.metadata.outputs.tags }}
|
||||||
|
build-args: |
|
||||||
|
ACCESS_TOKEN_USR=${{gitea.actor}}
|
||||||
|
ACCESS_TOKEN_PWD=${{gitea.token}}
|
||||||
37
Dockerfile
37
Dockerfile
@@ -1,28 +1,27 @@
|
|||||||
FROM golang:1.22-alpine AS builder
|
FROM golang:alpine as builder
|
||||||
|
|
||||||
WORKDIR /app
|
ARG ACCESS_TOKEN_USR="nothing"
|
||||||
|
ARG ACCESS_TOKEN_PWD="nothing"
|
||||||
|
|
||||||
# Copy go mod files
|
RUN apk add --no-cache ca-certificates tzdata git
|
||||||
COPY go.mod go.sum ./
|
|
||||||
|
|
||||||
# Download dependencies
|
WORKDIR /
|
||||||
RUN go mod download
|
|
||||||
|
# Create a netrc file using the credentials specified using --build-arg
|
||||||
|
RUN printf "machine git.coopgo.io\n\
|
||||||
|
login ${ACCESS_TOKEN_USR}\n\
|
||||||
|
password ${ACCESS_TOKEN_PWD}\n"\
|
||||||
|
>> ~/.netrc
|
||||||
|
RUN chmod 600 ~/.netrc
|
||||||
|
|
||||||
# Copy source code
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the application
|
RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
|
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM scratch
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
RUN apk --no-cache add ca-certificates
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||||
|
COPY --from=builder /server /
|
||||||
WORKDIR /root/
|
|
||||||
|
|
||||||
# Copy the binary from builder
|
|
||||||
COPY --from=builder /app/main .
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["/server"]
|
||||||
CMD ["./main"]
|
|
||||||
|
|||||||
142
README.md
Normal file
142
README.md
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
# Saved Search Service
|
||||||
|
|
||||||
|
A GRPC microservice for managing saved journey searches in the COOPGO platform. Users can save, retrieve, update, and delete their journey searches with departure/destination locations stored as GeoJSON features.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Create, read, update, and delete saved searches
|
||||||
|
- GeoJSON support for departure and destination locations
|
||||||
|
- Owner-based access control
|
||||||
|
- Paginated listing with filtering
|
||||||
|
- MongoDB storage backend
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Go 1.22+
|
||||||
|
- MongoDB
|
||||||
|
- Protocol Buffers compiler (for regenerating proto files)
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configuration is managed via Viper and can be set through a `config.yaml` file or environment variables.
|
||||||
|
|
||||||
|
### Default Configuration
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: "COOPGO Saved Search Service"
|
||||||
|
dev_env: false
|
||||||
|
|
||||||
|
storage:
|
||||||
|
db:
|
||||||
|
type: mongodb
|
||||||
|
mongodb:
|
||||||
|
host: localhost
|
||||||
|
port: 27017
|
||||||
|
db_name: coopgo_platform
|
||||||
|
collections:
|
||||||
|
saved_searches: saved_searches
|
||||||
|
|
||||||
|
services:
|
||||||
|
grpc:
|
||||||
|
enable: true
|
||||||
|
port: 8080
|
||||||
|
```
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
Configuration keys can be set via environment variables by replacing `.` with `_`:
|
||||||
|
|
||||||
|
- `STORAGE_DB_MONGODB_HOST` - MongoDB host
|
||||||
|
- `STORAGE_DB_MONGODB_PORT` - MongoDB port
|
||||||
|
- `SERVICES_GRPC_PORT` - GRPC server port
|
||||||
|
- `DEV_ENV` - Enable development mode (pretty logging)
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -o saved-search
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./saved-search
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
Build the Docker image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build \
|
||||||
|
--build-arg ACCESS_TOKEN_USR=<git_username> \
|
||||||
|
--build-arg ACCESS_TOKEN_PWD=<git_token> \
|
||||||
|
-t saved-search .
|
||||||
|
```
|
||||||
|
|
||||||
|
Run the container:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -p 8080:8080 saved-search
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
The service exposes a GRPC API with the following methods:
|
||||||
|
|
||||||
|
| Method | Description |
|
||||||
|
|--------|-------------|
|
||||||
|
| `CreateSavedSearch` | Create a new saved search |
|
||||||
|
| `GetSavedSearch` | Get a saved search by ID |
|
||||||
|
| `GetSavedSearchesByOwner` | Get all saved searches for an owner |
|
||||||
|
| `UpdateSavedSearch` | Update an existing saved search |
|
||||||
|
| `DeleteSavedSearch` | Delete a saved search |
|
||||||
|
| `ListSavedSearches` | List saved searches with pagination |
|
||||||
|
|
||||||
|
### SavedSearch Structure
|
||||||
|
|
||||||
|
```protobuf
|
||||||
|
message SavedSearch {
|
||||||
|
string id = 1;
|
||||||
|
string owner_id = 2;
|
||||||
|
SavedSearchGeoJsonFeature departure = 3;
|
||||||
|
SavedSearchGeoJsonFeature destination = 4;
|
||||||
|
google.protobuf.Timestamp datetime = 5;
|
||||||
|
google.protobuf.Struct data = 6;
|
||||||
|
google.protobuf.Timestamp created_at = 7;
|
||||||
|
google.protobuf.Timestamp updated_at = 8;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
saved-search/
|
||||||
|
├── main.go # Application entry point
|
||||||
|
├── config.go # Configuration management
|
||||||
|
├── core/
|
||||||
|
│ └── service/ # Business logic layer
|
||||||
|
├── data/
|
||||||
|
│ ├── types/ # Data types
|
||||||
|
│ └── storage/ # Storage implementations (MongoDB)
|
||||||
|
└── servers/
|
||||||
|
└── grpc/
|
||||||
|
├── proto/ # Protocol buffer definitions
|
||||||
|
└── server/ # GRPC server implementation
|
||||||
|
```
|
||||||
|
|
||||||
|
## Regenerating Proto Files
|
||||||
|
|
||||||
|
```bash
|
||||||
|
protoc --go_out=. --go-grpc_out=. servers/grpc/proto/saved-search.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This project is licensed under the GNU Affero General Public License v3.0 (AGPLv3).
|
||||||
Reference in New Issue
Block a user