I'm trying to create a Dockerfile to deploy a Vue.js app as a docker in Cloud Run (GCP). From the Vue official documentation and get a Dockerfile to deploy the app in a "production mode":
FROM node:lts-alpine
RUN npm install -g http-server
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "http-server", "dist" ]
It works properly but I want to modify the Dockerfile to make it dynamic. I mean, I want that this file is able to deploy either to production or to DEV using a kind of input parameter
I've tried several attempts, one of those was to add these new lines
ENV ENT=production
RUN NODE_ENV=${ENT} npm run build
With the intension to define a default value for the environment variable as "production", and in the Cloud Run service define the same environment variable as "dev". I thought the variable defined on the cloud run service will overwrite the local variable (Dockerfile) at the moment of running the docker. It was not overwritten and again the app is running in production
Do you know if there is a way to overwrite a Dockerfile environment variable or if It is possible to create something as
npm run build:dev
npm run build:prod
dynamically depending on the environment I want to deploy?
This is my package.json
{
/// ...
"scripts": {
"dev": "vue-cli-service serve --mode development",
"test": "cross-env NODE_ENV=testing vue-cli-service serve --mode testing",
"prod": "vue-cli-service serve --mode production",
"build:dev": "vue-cli-service build --mode development",
"build": "vue-cli-service build --mode production",
"lint": "vue-cli-service lint"
},
/// ...
}