Skip to content
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

Add Dockerfile #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tanishiking
Copy link

@tanishiking tanishiking commented Oct 24, 2023

#6

I'm also interested in build and running this app in container and deploy it to somewhere like CloudRun 😃

  • ./build-image.sh should archive the project and build it in docker container just docker build .

  • docker run ember-app to run the server in http://localhost:8080

  • However, the server gonna crash with the segmentation fault on receive the request and the container would hang. fixed

outdated
# Checking the process dies with segmentation fault in container
$ docker run -it ember-app:latest bash
root@5ef5f705125b:/app# apt update
...
root@5ef5f705125b:/app# apt install curl gdb -y
...
# Enable core dump
root@5ef5f705125b:/app# ulimit -c unlimited
root@5ef5f705125b:/app# cat /proc/sys/kernel/core_pattern
core

root@5ef5f705125b:/app# ./app &
[1] 2695
root@5ef5f705125b:/app# Starting Ember Example

root@5ef5f705125b:/app# curl http://localhost:8080
curl: (56) Recv failure: Connection reset by peer
[1]+  Segmentation fault      ./app

root@5ef5f705125b:/app# gdb app core
GNU gdb (Debian 10.1-1.7) 10.1.90.20210103-git
...
(No debugging symbols found in app)
[New LWP 2706]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
Core was generated by `./app'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00000000012debb4 in _SM42epollcat.unsafe.EventNotificationCallback$D7fromPtrL28scala.scalanative.unsafe.PtrL41epollcat.unsafe.EventNotificationCallbackEO ()
(gdb) backtrace
#0  0x00000000012debb4 in _SM42epollcat.unsafe.EventNotificationCallback$D7fromPtrL28scala.scalanative.unsafe.PtrL41epollcat.unsafe.EventNotificationCallbackEO ()
#1  0x0000000000bbe7f0 in _SM38epollcat.unsafe.EpollExecutorSchedulerD4pollL34scala.concurrent.duration.DurationzEO ()
#2  0x0000000000c78df0 in _SM43cats.effect.unsafe.PollingExecutorSchedulerD4loopuEPT43cats.effect.unsafe.PollingExecutorScheduler ()
#3  0x0000000000c786cc in _SM43cats.effect.unsafe.PollingExecutorSchedulerD27scheduleIfNeeded$$anonfun$1uEPT43cats.effect.unsafe.PollingExecutorScheduler ()
#4  0x0000000000a5817c in _SM53cats.effect.unsafe.PollingExecutorScheduler$$Lambda$2D3runuEO ()
#5  0x00000000012071a4 in _SM43scala.scalanative.runtime.ExecutionContext$D4loopuEO ()
#6  0x0000000000ee8c4c in _SM34scala.scalanative.runtime.package$D4loopuEO
    ()
#7  0x0000000000d597b8 in main ()

Any ideas? FYI @armanbilge

@tanishiking
Copy link
Author

Oh, wait. Once I upgraded the epollcat and http4s servers, it worked 🎉

@armanbilge
Copy link
Contributor

@tanishiking thanks for working on this!

FYI epollcat is heading towards deprecation, see armanbilge/epollcat#99.

Instead I recommend using this pre-release of FS2, then you can use IOApp instead of EpollApp.

@tanishiking
Copy link
Author

@armanbilge Thanks! awesome, I gonna check it out later 🎉

@armanbilge
Copy link
Contributor

Dockerfile Outdated
Comment on lines 47 to 52
FROM debian:11-slim
WORKDIR /app
COPY --from=build-env /build/target/scala-3.3.1/scala-native-ember-example-out ./app
# RUN ldd /app/app
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libssl-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*
Copy link
Contributor

@armanbilge armanbilge Oct 24, 2023

Choose a reason for hiding this comment

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

Instead of doing this it would be interesting if we could statically link openssl during the build process so we don't need to install it. This seems to be very challenging to do with the @link annotations unfortunately. That's why I think I intend to remove them in the next significant wave of releases.

@tanishiking
Copy link
Author

One last thing I'm struggling with is that I'm not familiar with TLS and s2n, and couldn't make it work correctly 🤔
When I run curl http://localhost:8080/joke the server gonna returns 500 because of fs2.io.net.tls.S2nException: Certificate is untrusted.

Maybe it's better to focus on finishing it without s2n for now like https://github.com/buntec/minimal-scala-native-http4s-server-app/

Dockerfile Outdated
Comment on lines 50 to 52
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libssl-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/*
Copy link
Contributor

Choose a reason for hiding this comment

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

One last thing I'm struggling with is that I'm not familiar with TLS and s2n, and couldn't make it work correctly 🤔
When I run curl http://localhost:8080/joke the server gonna returns 500 because of fs2.io.net.tls.S2nException: Certificate is untrusted.

Do you need to install ca-certificates maybe to fix that?

Copy link
Author

Choose a reason for hiding this comment

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

Ah, that's the case 😅 thanks!

@armanbilge
Copy link
Contributor

btw ... 😂 I just remembered we also have another example repository. might be interesting to look at.

@tanishiking tanishiking marked this pull request as ready for review October 30, 2023 07:15
@tanishiking tanishiking changed the title WIP: Add Dockerfile Add Dockerfile Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants