Skip to content

Commit

Permalink
Merge pull request #16 from isd-sgcu/dev
Browse files Browse the repository at this point in the history
Update main
  • Loading branch information
bookpanda authored Jan 4, 2024
2 parents 99dac40 + ced7d47 commit 19b794a
Show file tree
Hide file tree
Showing 27 changed files with 1,507 additions and 76 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Build

on:
workflow_dispatch:
push:
branches:
- main
- beta
- dev
- master

env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
IMAGE_TAG: ${{ github.sha }}

jobs:
build:
name: Build
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

outputs:
BRANCH: ${{ steps.branch.outputs.BRANCH }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Set branch
id: branch
run: |
echo "::set-output name=BRANCH::${GITHUB_REF#refs/heads/}"
- name: Log in to the Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }},${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
38 changes: 38 additions & 0 deletions .github/workflows/run-unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: 'Pull request/Push: Run unit test'

on:
pull_request:
branches:
- dev
- master
- main
- beta
push:
branches:
- dev
- master
- main
- beta

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Download dependencies
run: go mod download

- name: Vet
run: |
go vet ./...
- name: Test
run: |
go test -v -coverpkg ./src/app/... -coverprofile coverage.out -covermode count ./src/app/...
go tool cover -func="./coverage.out"
35 changes: 35 additions & 0 deletions .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 'Pull request/Push: Build test'

on:
pull_request:
branches:
- dev
- master
- main
- beta
push:
branches:
- dev
- master
- main
- beta

jobs:
docker-build:
name: 'Docker build and create an image'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build Docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: test
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ COPY --from=base /app/server ./
# Set ENV to production
ENV GO_ENV production

# Expose port 3001
EXPOSE 3001
# Expose port 3003
EXPOSE 3003

# Run the application
CMD ["./server"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ proto:

publish:
cat ./token.txt | docker login --username isd-team-sgcu --password-stdin ghcr.io
docker build . -t ghcr.io/isd-sgcu/johnjud-gateway
docker push ghcr.io/isd-sgcu/johnjud-gateway
docker build . -t ghcr.io/isd-sgcu/johnjud-backend
docker push ghcr.io/isd-sgcu/johnjud-backend

test:
go vet ./...
Expand Down
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,43 @@
# johnjud-backend
# Johnjud-backend

Johnjud-backend handles data management and business logic for the Johnjud project.

### What is Johnjud?
Johnjud is a pet adoption web application of the [CUVET For Animal Welfare Club](https://www.facebook.com/CUVETforAnimalWelfareClub)

## Stack

- golang
- gRPC
- postgresql

## Getting Started

### Prerequisites

- golang 1.21 or [later](https://go.dev)
- docker
- makefile

### Installation

1. Clone this repo
2. Copy every `config.example.yaml` in `config` and paste it in the same directory with `.example` removed from its name.

3. Run `go mod download` to download all the dependencies.

### Running
1. Run `docker-compose up -d`
2. Run `make server` or `go run ./src/.`

### Testing
1. Run `make test` or `go test -v -coverpkg ./... -coverprofile coverage.out -covermode count ./...`

## Other microservices/repositories of Johnjud
- [Johnjud-gateway](https://github.com/isd-sgcu/johnjud-gateway): Routing and request handling
- [Johnjud-auth](https://github.com/isd-sgcu/johnjud-auth): Authentication and authorization
- [Johnjud-backend](https://github.com/isd-sgcu/johnjud-backend): Main business logic
- [Johnjud-file](https://github.com/isd-sgcu/johnjud-file): File management service
- [Johnjud-proto](https://github.com/isd-sgcu/johnjud-proto): Protobuf files generator
- [Johnjud-go-proto](https://github.com/isd-sgcu/johnjud-go-proto): Generated protobuf files for golang
- [Johnjud-frontend](https://github.com/isd-sgcu/johnjud-frontend): Frontend web application
3 changes: 3 additions & 0 deletions config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ database:
name: johnjud_db
username: root
password: root

service:
file: localhost:3004
14 changes: 14 additions & 0 deletions config/file/config.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
app:
port: 3004
debug: true

database:
host: local-db
port: 5432
name: johnjud_db
username: root
password: root

s3:
bucket_name: <bucket name>
region: <region>
13 changes: 12 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
version: "3.9"

services:
local-file:
image: ghcr.io/isd-sgcu/johnjud-file
container_name: file
depends_on:
- local-db
restart: unless-stopped
volumes:
- ./config/file:/app/config
ports:
- "3004:3004"

local-db:
image: postgres:15.1-alpine3.17
container_name: johnjud-local-db
Expand All @@ -12,7 +23,7 @@ services:
volumes:
- postgres:/var/lib/postgresql/data
ports:
- "5433:5432"
- "5432:5432"

volumes:
postgres:
26 changes: 17 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,41 @@ go 1.21.3
toolchain go1.21.5

require (
github.com/bxcodec/faker/v3 v3.8.1
github.com/google/uuid v1.5.0
github.com/isd-sgcu/johnjud-go-proto v0.0.9
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.60.1
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/stretchr/objx v0.5.0 // indirect
golang.org/x/net v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.32.0 // indirect
)

require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/isd-sgcu/johnjud-go-proto v0.0.8 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
Expand All @@ -39,12 +51,8 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -18,8 +20,8 @@ github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/isd-sgcu/johnjud-go-proto v0.0.8 h1:nIQBZgK2OFVrLjVtpeDgwows8poA7LhsIVE4hlbBC1o=
github.com/isd-sgcu/johnjud-go-proto v0.0.8/go.mod h1:HP0w9gC30b5WNnqeFBM9JJZud+pvyikz0+pGFSI/Wjw=
github.com/isd-sgcu/johnjud-go-proto v0.0.9 h1:cFfZ2JSpW0jg94Iv5zHQJGnoekj0eCQe42SJaTpnp3c=
github.com/isd-sgcu/johnjud-go-proto v0.0.9/go.mod h1:1OK6aiCgtXQiLhxp0r6iLEejYIRpckWQZDrCZ9Trbo4=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
Expand Down Expand Up @@ -71,6 +73,7 @@ github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down Expand Up @@ -98,15 +101,14 @@ golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 h1:wpZ8pe2x1Q3f2KyT5f8oP/fa9rHAKgFPr/HZdNuS+PQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f h1:ultW7fxlIvee4HYrtnaRPon9HpEgFk5zYpmfMgtKB5I=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc=
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
16 changes: 0 additions & 16 deletions src/app/model/adopt/adopt.model.go

This file was deleted.

8 changes: 4 additions & 4 deletions src/app/model/common.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

type Base struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;size:191"`
CreatedAt time.Time `json:"created_at" gorm:"type:datetime;autoCreateTime:nano"`
UpdatedAt time.Time `json:"updated_at" gorm:"type:datetime;autoUpdateTime:nano"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index;type:datetime"`
ID uuid.UUID `json:"id" gorm:"primary_key"`
CreatedAt time.Time `json:"created_at" gorm:"type:timestamp;autoCreateTime:nano"`
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamp;autoUpdateTime:nano"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index;type:timestamp"`
}

func (m *Base) BeforeCreate(_ *gorm.DB) error {
Expand Down
1 change: 1 addition & 0 deletions src/app/model/pet/pet.model.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ type Pet struct {
Background string `json:"background" gorm:"tinytext"`
Address string `json:"address" gorm:"tinytext"`
Contact string `json:"contact" gorm:"tinytext"`
AdoptBy string `json:"adopt_by" gorm:"tinytext"`
}
Loading

0 comments on commit 19b794a

Please sign in to comment.