Skip to content

Commit

Permalink
made /storage writable
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 29, 2023
1 parent fd832a0 commit c7c4c5f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/localServer/localTestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func main() {
if err != nil {
log.WithError(err).Error("error sending feedback occurred")
} else {
log.Info("Success %s", feedback.Status)
log.Info("Success ", feedback.Status)
}
}
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ services:
- SMTP_URL=${SMTP_URL:-postout.lrz.de}
- SMTP_USERNAME=${SMTP_USERNAME:[email protected]}
- SMTP_PORT=${SMTP_PORT:-587}
user: 1000:3000
volumes:
- backend-storage:/Storage
- ./apns_auth_key.p8:${APNS_P8_FILE_PATH}
depends_on:
db:
Expand All @@ -42,4 +44,6 @@ services:

volumes:
campus-db-data:
driver: local
backend-storage:
driver: local
8 changes: 8 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ COPY --from=builder /backend /backend
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /etc/passwd /etc/passwd

# make sure that /Storage is mounted with the correct access permissions even in docker-compose
RUN mkdir /Storage
RUN chown appuser /Storage
VOLUME /Storage

# Use an unprivileged user
USER appuser

# documentation for docker-compose
EXPOSE 50051

# Run the main binary
CMD ["/backend"]
21 changes: 14 additions & 7 deletions server/backend/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"
"io"
"os"
"path/filepath"
)

func (s *CampusServer) SendFeedback(ctx context.Context, req *pb.SendFeedbackRequest) (*emptypb.Empty, error) {
Expand Down Expand Up @@ -66,31 +67,37 @@ func (s *CampusServer) SendFeedbackImage(stream pb.Campus_SendFeedbackImageServe
for {
req, err := stream.Recv()
if finalDestination == "" {
finalDestination = fmt.Sprintf("feedback/%d/%d", req.GetId(), req.GetImageNr())
finalDestination = fmt.Sprintf("/Storage/feedback/%d/%d.png", req.GetId(), req.GetImageNr())
}
if err == io.EOF {
break
}
if err != nil {
log.WithError(err).Error("failed to recive feedbackImage %s", finalDestination)
log.WithError(err).Errorf("failed to recive feedbackImage %s", finalDestination)
return status.Error(codes.Aborted, err.Error())
}
content := req.GetContent()
bytesWritten, err := file.Write(content)
log.Debug("received a chunk with size: %d", bytesWritten)
fileSize += bytesWritten
log.Info("received a chunk with size: ", bytesWritten)
if err != nil {
log.WithError(err).Error("failed to write chunk for feedbackImage %s", finalDestination)
log.WithError(err).Error("failed to write chunk for feedbackImage ", finalDestination)
return status.Error(codes.ResourceExhausted, err.Error())
}
}
log.Debug("saved file: %s, size: %d", file.Name(), fileSize)
log.Infof("saved file: %s, size: %d", file.Name(), fileSize)

// move the file to a different directory
parent := filepath.Dir(finalDestination)
if err = os.MkdirAll(parent, os.ModePerm); err != nil {
log.WithError(err).Error("failed to make all directories of ", finalDestination)
return err
}
if err := os.Rename(file.Name(), finalDestination); err != nil {
log.WithError(err).Error("could not move %s to %s", file.Name(), finalDestination)
log.WithError(err).Errorf("could not move %s to %s", file.Name(), finalDestination)
return status.Error(codes.Internal, err.Error())
}
log.Debug("changed files directory to %s", finalDestination, fileSize)
log.Infof("changed file's (%dB) directory to %s", fileSize, finalDestination)

return nil
}

0 comments on commit c7c4c5f

Please sign in to comment.