bldg14 / eventual

A simple event calendar
https://eventual-client.fly.dev
MIT License
0 stars 0 forks source link

Enable automatic deployment of client #37

Closed kevinfalting closed 11 months ago

kevinfalting commented 12 months ago

Issue Description

With https://github.com/bldg14/eventual/pull/36, we're automatically deploying the server to fly.io via a GitHub action. We should setup the auto deploy for the client as well. It should deploy from main on any merge to main, so basically the same rules as the server.

I'm hoping to stay in the free tier of fly.io.

Supporting Documentation

We're set up as a monorepo, so we can reference this documentation: https://fly.io/docs/reference/monorepo/

Implementation Details

Let's write a dockerfile for the client so it's built with everything it needs and then runs in a minimal from scratch container similar to how we did the server.

Acceptance Criteria

  1. The client has a Dockerfile describing a very minimal build process.
  2. The client is automatically deployed via GitHub actions.
kevinfalting commented 11 months ago

I tried going down the path of a distroless build, and I could get it working locally, but for some reason the fly servers just couldn't get it to run, and I ran out of patience. It was an unnecessary fafo, but here's as far as I got:

Dockerfile.client ```Dockerfile ARG NODE_VERSION=18 FROM node:${NODE_VERSION} as builder WORKDIR /app COPY package.json package-lock.json ./ RUN npm install --omit="dev" COPY . . RUN npm run build FROM nginxinc/nginx-unprivileged as nginx # The following blog was a helpful starting point: # https://andrewrea.co.uk/posts/distroless-nginx/ # ldd $(which nginx) # linux-vdso.so.1 (0x00007ffebd5fd000) # libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f8f856d7000) # libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f8f8563d000) # libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x00007f8f85594000) # libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f8f85113000) # libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f8f850f4000) # libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8f84f11000) # /lib64/ld-linux-x86-64.so.2 (0x00007f8f85950000) FROM gcr.io/distroless/base-debian10:nonroot COPY --from=nginx /etc/passwd /etc/passwd COPY --from=nginx /etc/group /etc/group COPY --from=nginx /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2 COPY --from=nginx /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6 COPY --from=nginx /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1 COPY --from=nginx /lib/x86_64-linux-gnu/libcrypt.so.1 /lib/x86_64-linux-gnu/libcrypt.so.1 COPY --from=nginx /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0 COPY --from=nginx /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 COPY --from=nginx /usr/lib/x86_64-linux-gnu/libssl.so.3 /usr/lib/x86_64-linux-gnu/libssl.so.3 COPY --from=nginx /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0 /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0 COPY --from=nginx /usr/lib/x86_64-linux-gnu/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/libcrypto.so.3 COPY --from=nginx /var/log/nginx /var/log/nginx COPY --from=nginx --chown=nginx:nginx --chmod=+x /usr/sbin/nginx /usr/sbin/nginx COPY --chown=nginx:nginx nginx.client.conf /etc/nginx/nginx.conf COPY --from=builder /app/build/ /www/data/ EXPOSE 8080 USER nginx ENTRYPOINT ["/usr/sbin/nginx", "-g", "daemon off;"] ```
fly.io monitoring logs ```sh dfw [info] Pulling container image registry.fly.io/eventual-client:deployment-01H9GFAB0WXDN83B0AQHGM39KW dfw [info] Successfully prepared image registry.fly.io/eventual-client:deployment-01H9GFAB0WXDN83B0AQHGM39KW (1.668004318s) dfw [info] Configuring firecracker dfw [info] [ 0.036424] PCI: Fatal: No config space access function found dfw [info] INFO Starting init (commit: 5293a085)... dfw [info] INFO Preparing to run: `/usr/sbin/nginx -g daemon off;` as nginx dfw [info] ERROR Error: failed to spawn command: /usr/sbin/nginx -g daemon off;: Permission denied (os error 13) dfw [info] does `/usr/sbin/nginx` exist and is it executable? dfw [info] [ 0.223831] reboot: Restarting system dfw [warn] Virtual machine exited abruptly dfw [info] machine exited with exit code 0, not restarting ```

For now, I'll skip the distroless part and just use the official unprivileged nginx image, which appears to work.