Added docker file

main-old
Antonio De Lucreziis 2 years ago
parent dc53ee66cb
commit cb76d0cdf2

@ -0,0 +1,24 @@
FROM node:18 AS frontend-builder
WORKDIR /frontend
COPY ./frontend/package.json ./package.json
COPY ./frontend/package-lock.json ./package-lock.json
RUN npm install
COPY ./frontend .
RUN make
FROM golang:1.18-alpine AS backend-builder
WORKDIR /backend
COPY go.mod go.sum ./
RUN go mod download -x
COPY . .
RUN go build -buildvcs=false -o website-server -v .
FROM alpine:latest AS runner
WORKDIR /app
COPY --from=frontend-builder /frontend/dist ./frontend/dist
COPY --from=backend-builder / ./website-server
COPY ./views ./views
COPY ./news ./news
COPY ./public ./public
EXPOSE 8000
CMD ["./website-server"]

@ -37,7 +37,7 @@ $ git clone https://git.phc.dm.unipi.it/phc/website
$ cd frontend/ $ cd frontend/
frontend/ $ npm install frontend/ $ npm install
frontend/ $ cd .. frontend/ $ cd ..
$ make js $ make frontend
``` ```
## Development ## Development
@ -66,9 +66,9 @@ $ fd -e go | entr -r go run .
Se si sta anche modificando codice dentro `frontend/`, in contemporanea serve anche fare Se si sta anche modificando codice dentro `frontend/`, in contemporanea serve anche fare
```bash shell ```bash shell
$ make js $ make frontend
# O anche con un watcher... # O anche con un watcher...
$ fd -e js | entr make js $ fd -e js | entr make frontend
``` ```
### Environment Variables ### Environment Variables

@ -32,7 +32,7 @@ type Session struct {
Token string `json:"token"` Token string `json:"token"`
} }
// AuthenticatorService can login users using a separate http service or a temporary in memory store. When a user logs in the auth service returns a session token that can be used to read and modify user properties without having to re-send the user password. (TODO: Not yet implemented: this token has to be renewed every so often otherwise it lasts just a couple of days) // AuthenticatorService can login users using a separate http service or a temporary in memory store. When a user logs in the auth service returns a session token that can be used to read and modify user properties without having to re-send the user password. (TODO: Not yet implemented, this token has to be renewed every so often otherwise it lasts just a couple of days)
type AuthenticatorService interface { type AuthenticatorService interface {
// GetUser retrieves the user info given the username // GetUser retrieves the user info given the username
GetUser(username string) (*User, error) GetUser(username string) (*User, error)

@ -11,8 +11,11 @@ import (
// ldapUser represents an LDAP User, most fields are inherited from [auth.User] // ldapUser represents an LDAP User, most fields are inherited from [auth.User]
type ldapUser struct { type ldapUser struct {
User Uid string `json:"username"`
NumericId int `json:"id"` NumericId int `json:"id"`
Name string `json:"name"`
Surname string `json:"surname"`
Email string `json:"email"`
Role string `json:"role"` Role string `json:"role"`
Gecos string `json:"gecos"` Gecos string `json:"gecos"`
} }
@ -20,11 +23,10 @@ type ldapUser struct {
// AsUser converts an [ldapUser] to an instance of [auth.User] // AsUser converts an [ldapUser] to an instance of [auth.User]
func (u ldapUser) AsUser() *User { func (u ldapUser) AsUser() *User {
return &User{ return &User{
Username: u.Username, Username: u.Uid,
Name: u.Name, Name: u.Name,
Surname: u.Surname, Surname: u.Surname,
Email: u.Email, Email: u.Email,
FullName: u.Gecos, FullName: u.Gecos,
} }
} }
@ -37,7 +39,7 @@ type LDAPAuthService struct {
// doGetRequest is a utility to make HTTP GET requests // doGetRequest is a utility to make HTTP GET requests
func (a *LDAPAuthService) doGetRequest(url string, response interface{}) error { func (a *LDAPAuthService) doGetRequest(url string, response interface{}) error {
req, err := http.NewRequest( req, err := http.NewRequest(
"GET", path.Join(a.Host, "ldap", url), bytes.NewBuffer([]byte("")), "GET", path.Join(a.Host, "poisson-ldap", url), bytes.NewBuffer([]byte("")),
) )
if err != nil { if err != nil {
@ -92,7 +94,7 @@ func (a *LDAPAuthService) GetUser(username string) (*User, error) {
func (a *LDAPAuthService) GetUsers() ([]*User, error) { func (a *LDAPAuthService) GetUsers() ([]*User, error) {
ldapUsers := []*ldapUser{} ldapUsers := []*ldapUser{}
if err := a.doGetRequest(fmt.Sprintf("/users"), &ldapUsers); err != nil { if err := a.doGetRequest("/users", &ldapUsers); err != nil {
return nil, err return nil, err
} }
@ -120,7 +122,7 @@ func (a *LDAPAuthService) Login(username, password string) (*Session, error) {
} }
var response Session var response Session
if err := a.doPostRequest(fmt.Sprintf("/login"), reqBody, &response); err != nil { if err := a.doPostRequest("/login", reqBody, &response); err != nil {
return nil, err return nil, err
} }

@ -75,7 +75,7 @@ func main() {
} }
app.Get("/api/utenti", func(c *fiber.Ctx) error { app.Get("/api/utenti", func(c *fiber.Ctx) error {
utenti, err := GetUtenti() utenti, err := authService.GetUsers()
if err != nil { if err != nil {
return err return err
} }

Loading…
Cancel
Save