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

I-36 Use pre-built frontend image instead of building Next.js app on boot #80

Merged

Conversation

reginaldbondoc
Copy link
Contributor

@reginaldbondoc reginaldbondoc commented Dec 5, 2022

Frontend changes

  • New Dockerfile for building images
    • Now multi-stage
    • NODE_ENV value production pre-baked
    • POSTHOG_HOST pre-baked with value https://app.posthog.com (can be overwritten during build via build-arg)
    • POSTHOG_API_KEY will be pre-baked with "public" PostHog API key during build via build-arg. Now, self-hosted clients will already have this set in the image they pull.
    • Final production image has the optimized Next.js application, i.e. using the standalone files
    • On boot, some environment variables may override during runtime
      • NEXT_PUBLIC_POSTHOG_API_KEY - when set, will replace the pre-baked one. One application of this is for the cloud-hosted clients, where we want to use the "private" PostHot API key
      • INFISICAL_TELEMETRY_ENABLED (TELEMETRY_ENABLED in .env file setting the value of INFISICAL_TELEMETRY_ENABLED in docker-compose) - when set to false, will disable Infisical telemetry. Enabled by default.
      • Note on value of INFISICAL_TELEMETRY_ENABLED or TELEMETRY_ENABLED: Only the string false will disable telemetry. Any other value, including empty string, will enable telemetry.
    • Starts the application via node instead of next (the latter has issue with SIGTERM)
  • Created separate singleton utility class Telemetry
    • Initialization of PostHog API (only when telemetry is enabled) will be done only once in this class
  • Modified usages of posthog API to use the singleton Telemetry class

Compose files changes

  • docker-compose.yml
    • Removed the platform qualifier as this PR includes support for building multi-platform images (see changes to GitHub Actions workflow below)
    • Removed build definition for both backend and frontend services - we should be using the images instead of building (please correct me here if I'm wrong)
    • Removed unused environment variables
  • docker-compose.dev.yml
    • Removed image property as we're building on boot anyway
    • Removed unused environment variables
    • Added dependency to mongo of mongo-express

GitHub Actions workflow changes

  • Improved docker-image workflow
  • Separated into backend and frontend jobs. Now, frontend can build in parallel even when some backend build steps fail.
  • Support for multi-platform (amd64 & arm64)
  • Added test step to run the built image before actually pushing to Docker Hub (Note: the second build step does not actually build from scratch, as the layers for amd64 are cached. Only the arm64 will be built anew)

@reginaldbondoc reginaldbondoc changed the title I-36 use pre built frontend image I-36 Use pre-built frontend image instead of building on boot Dec 6, 2022
@reginaldbondoc reginaldbondoc changed the title I-36 Use pre-built frontend image instead of building on boot I-36 Use pre-built frontend image instead of building Next.js app on boot Dec 6, 2022
@maidul98 maidul98 self-requested a review December 6, 2022 00:04
@maidul98
Copy link
Collaborator

maidul98 commented Dec 6, 2022

Hey Egi, i am still reviewing the changes! Really good stuff

maidul98
maidul98 previously approved these changes Dec 6, 2022
Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Looks go to me! Ping me if the git workflow is not working as expected so we can take a look together

Copy link
Collaborator

@maidul98 maidul98 left a comment

Choose a reason for hiding this comment

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

Looks good!

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.

Build frontend within image build process and inject envars into containers at runtime
2 participants