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/
frontend/ $ npm install
frontend/ $ cd ..
$ make js
$ make frontend
```
## 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
```bash shell
$ make js
$ make frontend
# O anche con un watcher...
$ fd -e js | entr make js
$ fd -e js | entr make frontend
```
### Environment Variables

@ -32,7 +32,7 @@ type Session struct {
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 {
// GetUser retrieves the user info given the username
GetUser(username string) (*User, error)

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

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

Loading…
Cancel
Save