I have a simple express app I am attempting to deploy on GKE.
When I build and run locally, everything is running as expected.
When I deploy via kubectl on GKE however, I get..
sh: 1: babel: not found
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! express-api@1.0.0 prestart: `npm run -s build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the express-api@1.0.0 prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
My deployement yaml file is as follows..
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: express-api
spec:
replicas: 2
minReadySeconds: 15
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: express-api
deployment: express-api-deployment
spec:
containers:
- name: express-api
image: pggriff/express-api:0.0.0-dev102
imagePullPolicy: Always
ports:
- containerPort: 3000
protocol: TCP
readinessProbe:
httpGet:
path: /meta
port: 3000
periodSeconds: 1
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 10
---
apiVersion: v1
kind: Service
metadata:
name: express-svc
spec:
type: NodePort
selector:
app: express-api
ports:
- protocol: TCP
port: 80
targetPort: 3000
My Dockerfile looks like..
FROM node:carbon
RUN npm install -g pm2
WORKDIR /usr/src/app
COPY package*.json ./
ARG TARGET_ENV
COPY .env.$TARGET_ENV .env
COPY . .
EXPOSE 8080
CMD [ "npm", "start"]
My Package.json has the following scripts..
"scripts": {
"test": "cross-env NODE_ENV=test nodemon --exec mocha ./**/*.spec.js --compilers js:babel-core/register",
"dev": "cross-env NODE_ENV=dev nodemon -w src --exec \"babel-node src --presets env,stage-0\"",
"build": "babel src -s -D -d dist --presets env,stage-0",
"start": "cross-env NODE_ENV=production pm2-runtime dist",
"prestart": "npm run -s build",
"clean": "rimraf dist/",
"build:dev": "bash scripts/build-dev.sh",
"deploy:dev": "bash scripts/deploy-dev.sh"
},
And I have the following dependencies..
"dependencies": {
"babel": "^6.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"body-parser": "^1.18.2",
"cors": "^2.8.4",
"cross-env": "^5.1.4",
"dotenv": "^5.0.1",
"express": "^4.16.3",
"helmet": "^3.12.0"
},
"devDependencies": {
"chai": "^4.1.2",
"mocha": "^5.1.1",
"morgan": "^1.9.0",
"nodemon": "^1.17.3",
"rimraf": "^2.6.2",
"supertest": "^3.0.0"
}
I also have a bash script set up to handle the deploy for, which looks like..
if [ -z "$1" ]; then
echo "Missing version / tag"
exit
fi
echo "Deploying $1"
docker build --build-arg TARGET_ENV=dev -t pggriff/express-api:$1 . &&
gcloud config set project foo-project &&
gcloud container clusters get-credentials dev-cluster --zone europe-west4-a &&
gcloud docker -- push pggriff/express-api:$1 &&
kubectl apply -f deployment.dev.yaml
I'd accidentally deleted the npm install command from my docker file