Here is a memo for deployment. It skips lots of detail and only focus on nuxt3 project setup.
First, get started with web project settings to understand how to start a server in dockerfile.
There are there scripts required in deployment.
build
: Build nitro server in production. If there is variable that is not runtime env, pass it as env arg.start
: Start nitro server in production. If there is variable that is runtime env, pass it as env arg.coverage
: Run overall vitest to get coverage report. It's useful to prepare report for sonarqube.Create a dotenv file for production env.
(Please be careful NOT to expose private variables in commit. If you need to pass private variables, put them through env while launching docker image.)
Although it's not recommended by nuxt official. You can use hecky way to export dotenv file variables and then start the nitro server if your team relies on it to manage different environment variables. Let me show you how to do it.
Handle launching server command in dockerfile. Using a bash script to start server at entrypoint.
Then, export env varirables by phase as NODE_ENV variables and start nitro server.
Then, go further more to create a github action workflow to build web application and build docker image based on previous section.
The main concept is:
web-app.dockerfile
.Finally, pass PHASE
while initializing a docker container so it can run the server with env variables.
Here is the ingress config in another k8s manifest repo.
That's all! Feel free to copy the template and modify it as you wish.
Work
Nuxt3
Github Workflow
Docker