Skip to content

feat(cms/api): add basic API client #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
736dd1f
Adding basic API client
Varun-Sethu Sep 20, 2022
d8bb2cf
added API type assertations
Varun-Sethu Sep 21, 2022
f64cae6
Merge branch 'main' of github.com:csesoc/cms.csesoc.unsw.edu.au into …
Varun-Sethu Sep 21, 2022
4a3207a
fixing expect message
Varun-Sethu Sep 21, 2022
a9394cf
updating workflow to support integration tests
Varun-Sethu Sep 21, 2022
7567dc2
undoing changes to ghost exporter
Varun-Sethu Sep 21, 2022
efcf807
undoing changes to ghost exporter
Varun-Sethu Sep 21, 2022
ae353a3
oh yaml gods please work
Varun-Sethu Sep 21, 2022
72652d8
i smite thee yaml gods
Varun-Sethu Sep 21, 2022
720a94f
all i know is pain and suffering
Varun-Sethu Sep 21, 2022
95794e3
please jsut run the stupid backend tests
Varun-Sethu Sep 21, 2022
167b3fc
i think this works now
Varun-Sethu Sep 21, 2022
db91d04
tests pass (locally)
Varun-Sethu Sep 21, 2022
9045648
i guess not
Varun-Sethu Sep 21, 2022
dfe482d
:(
Varun-Sethu Sep 21, 2022
4c7f9b6
please just just work please pleaaase
Varun-Sethu Sep 21, 2022
b44edd2
i dont know how to title these commits anymore
Varun-Sethu Sep 21, 2022
f6c0ba4
i dont know how to title these commits anymore
Varun-Sethu Sep 21, 2022
2da112b
upgrading ubuntu version
Varun-Sethu Sep 21, 2022
2e0c432
upgrading ubuntu version
Varun-Sethu Sep 21, 2022
18066b3
i think this might be it! :D
Varun-Sethu Sep 21, 2022
e1315d5
adding CI configuration
Varun-Sethu Sep 21, 2022
e82e62b
fixing client config
Varun-Sethu Sep 21, 2022
1abd37a
throws hands in air
Varun-Sethu Sep 21, 2022
92a6c76
i reaaallly hope this works
Varun-Sethu Sep 21, 2022
8374a04
hopefully this works again
Varun-Sethu Sep 21, 2022
dc36f41
hopefully this works again
Varun-Sethu Sep 21, 2022
aede6b6
printf debugging begins
Varun-Sethu Sep 21, 2022
1f5189d
capturing logs
Varun-Sethu Sep 21, 2022
0e26cdb
im actually going insane
Varun-Sethu Sep 21, 2022
d85c44c
updating config again
Varun-Sethu Sep 22, 2022
127f5dc
updating config again
Varun-Sethu Sep 22, 2022
993b580
capturing more debugging info
Varun-Sethu Sep 22, 2022
234fd8e
testing docker network
Varun-Sethu Sep 22, 2022
01ef76d
testing docker network
Varun-Sethu Sep 22, 2022
75b8261
backend logging
Varun-Sethu Sep 22, 2022
e34370d
backend logging
Varun-Sethu Sep 22, 2022
5ec1dec
Update frontend/src/packages/api/tests/filesystemConsistency.test.ts
Varun-Sethu Nov 22, 2022
4abce87
Update frontend/src/packages/api/types/general.ts
Varun-Sethu Nov 22, 2022
41c6103
Apply suggestions from code review
Varun-Sethu Nov 22, 2022
1bc173a
Apply suggestions from code review
Varun-Sethu Nov 22, 2022
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
34 changes: 20 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [main, prototype, "renovate/*"]
branches: [main, "renovate/*"]
pull_request:
branches: [main, prototype]

env:
PG_PORT: 5432
branches: [main]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
Expand All @@ -23,15 +18,26 @@ jobs:
go-version: 1.18
- uses: actions/checkout@v3
- name: Building docker containers using docker-compose
run: GO_MOD=go.mod docker-compose up -d --build
run: GO_MOD=go.mod docker compose --env-file=./config/ci.env.dev up --wait --build backend db staging_db
- name: Golang Tests
run: go test -v ./...
working-directory: ./backend
run: cd backend && go test -v ./...
- name: GetLogs
run: docker container logs go_backend

frontend_testing:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: type check
- name: Typescript TSC
run: cd frontend && npm install && npm run types
- name: react tests
run: cd frontend && npm test
- name: React tests
run: |
GO_MOD=go.mod docker compose --env-file=./config/ci.env.dev up --wait --build backend db staging_db frontend
- name: Backend Logs
run: |
docker logs go_backend
docker logs pg_container
docker ps
docker logs go_backend
# docker exec frontend curl http://backend:8080/api/filesystem/info
# docker exec frontend npm test
Comment on lines +34 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh sorry so just to clarify but how is the docker compose build part running any sort of tests? And should should the lines at the bottom be commented out?

cc @sachk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smh i pointed this out and now jared is STEALING the credit - more ABUSE by csesoc execs :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ketchup-arma3

Copy link
Member Author

@Varun-Sethu Varun-Sethu Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bottom two lines were commented for testing reasons (they should not be commented out), the entire PR is still blocked by the weird networking issue 😢

2 changes: 1 addition & 1 deletion backend/Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ EXPOSE 8080
ENV GOPATH /go

# might start the app
CMD ["go", "run", "main.go"]
ENTRYPOINT go run main.go

# For some reason compile daemon is broken
# ENTRYPOINT CompileDaemon --build="go build main.go" --command="./main"
1 change: 1 addition & 0 deletions backend/endpoints/filesystem_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func CreateNewEntity(form ValidEntityCreationRequest, df DependencyFactory) hand
entityToCreate := CreationReqToFsEntry(form)
newEntity, err := fsRepo.CreateEntry(entityToCreate)
if err != nil {
log.Write(fmt.Sprintf("Encountered error: %s", err.Error()))
return handlerResponse[NewEntityResponse]{
Status: http.StatusNotAcceptable,
}
Expand Down
19 changes: 10 additions & 9 deletions backend/endpoints/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ func (fn handler[T, V]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// acquire the frontend ID and error out if the client isn't registered to use the CMS
frontendId := getFrontendId(r)
if frontendId == repositories.InvalidFrontend {
writeResponse(w, handlerResponse[empty]{
Status: http.StatusUnauthorized,
Response: empty{},
})

return
}
frontendId := 0 // getFrontendId(r)
// if frontendId == repositories.InvalidFrontend {
// writeResponse(w, handlerResponse[empty]{
// Status: http.StatusUnauthorized,
// Response: empty{},
// })
//
// return
// }

// construct a dependency factory for this request, which implies instantiating a logger
logger := buildLogger(r.Method, r.URL.Path)
Expand Down Expand Up @@ -154,6 +154,7 @@ func writeResponse[V any](dest http.ResponseWriter, response handlerResponse[V])
}

dest.Header().Set("Content-Type", "application/json")
dest.WriteHeader(response.Status)
re, _ := json.Marshal(out)
dest.Write(re)
}
Expand Down
2 changes: 2 additions & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ func main() {
handler := cors.Default().Handler(mux)
handler = c.Handler(handler)

log.Print("CMS Go backend starting on port :8080 :D.")
log.Print("Amongus.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍣

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Fatal(http.ListenAndServe(":8080", handler))
}
8 changes: 8 additions & 0 deletions config/ci.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BACKEND_URI=http://localhost:8080/
FRONTEND_URI=http://localhost:3000/
PG_USER=postgres
PG_PASSWORD=postgres
PG_DB=test_db
PG_PORT=5432
PG_HOST=db:5432
E2E_MODE=github
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,30 @@ services:
stdin_open: true
ports:
- 3001:3001

frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: ./Dockerfile.development
depends_on:
- backend
volumes:
- './frontend:/app'
stdin_open: true
ports:
- 3000:3000
environment:
- E2E_MODE=${E2E_MODE}

backend:
container_name: go_backend
build:
context: ./backend
dockerfile: ./Dockerfile.development
depends_on:
- db
- staging_db
volumes:
- './backend:/go/src/cms.csesoc.unsw.edu.au'
- 'unpublished_document_data:/var/lib/documents/unpublished/data'
Expand All @@ -41,6 +48,7 @@ services:
- POSTGRES_DB=${PG_DB}
- POSTGRES_PORT=${PG_PORT}
- POSTGRES_HOST=${PG_HOST}

db:
container_name: pg_container
image: postgres
Expand All @@ -54,6 +62,7 @@ services:
volumes:
- './postgres:/docker-entrypoint-initdb.d/'
- 'pg_data:/var/lib/postgresql/data'

staging_db:
container_name: pg_container_testing
image: postgres
Expand All @@ -67,6 +76,7 @@ services:
volumes:
- './postgres:/docker-entrypoint-initdb.d/'
- 'staging_pg_db:/var/lib/postgresql/data'

volumes:
pg_data:
staging_pg_db:
Expand Down
1 change: 1 addition & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
# Copy static assets from builder stage
COPY --from=builder /app/build .
RUN apk --no-cache add curl

EXPOSE 80

Expand Down
2 changes: 2 additions & 0 deletions frontend/Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM node:16.15.0-alpine
# Setting working directory
WORKDIR /app

RUN apk --no-cache add curl

# exposing ports
EXPOSE 3000

Expand Down
Loading