Github Action CI - how to deploy app to heroku? - node.js

I have a trouble with deploying app to heroku with using Github Action and Docker, here is my main.yml:
name: Deploy
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: akhileshns/heroku-deploy#v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
can someone tell me what have I wrong here? During running deployment job I'm facing with this issue:
here is also my Dockerfile and docker-compose:
docker-compose.yml
version: '3.7'
networks:
proxy:
external: true
services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
command: ["redis-server", "--requirepass", "redisPass12345!"]
networks:
- proxy
worker:
container_name: name
build:
context: .
dockerfile: Dockerfile
depends_on:
- redis
ports:
- 8080:8080
expose:
- '8080'
env_file:
- .env
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
command: npm run dev
networks:
- proxy
dockerfile
FROM node:12.17-alpine as builder
WORKDIR /dist
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 8080
CMD [ "npm", "run", "dev"]
package.json
"build": "nest build",
"dev": "node dist/main.js",
Thanks for any help!

Related

docker don't add new package in node_moudel nestJS project

my Dockerfile && docker-compose && docker log
my docker-compose
admin:
build:
context: ./src
dockerfile: Dockerfile
command: npm run start:dev
container_name: nestjs
ports:
- "8080:3000"
image: node:16
volumes:
- ./src:/usr/src/app/src
- ./src:/usr/src/app/src/node_modules
restart: always
tty: true
working_dir: /usr/src/app/src
my dockerfile
https://ibb.co/wWqDLCn
my dockerlog
https://ibb.co/f21S3dW

Nest js Docker Cannot find module dist/main

I am building a Nest.js App using Docker-compose.
The problem is when I tried "docker-compose up prod" then it shows "Error: Cannot find module '/usr/src/app/dist/main."
Thus, I explored the files in the image of the prod, but I could find the dist folder. Also, I run dist/main and it works. However, I tried docker-compose up prod, it shows the above error.
Moreover, when I tried "docker-compose up dev." It works perfectly, making a dist folder to the host machine. The main difference between the dev and prod is the command that dev is using npm run start:dev, but prod is using npm run start:prod.
This is My DockerFile
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install rimraf
RUN npm install --only=development
COPY . .
RUN npm run build
FROM node:12.19.0-alpine3.9 as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
This is my docker-compose.yaml
services:
proxy:
image: nginx:latest # 최신 버전의 Nginx 사용
container_name: proxy # container 이름은 proxy
ports:
- '80:80' # 80번 포트를 host와 container 맵핑
networks:
- nestjs-network
volumes:
- ./proxy/nginx.conf:/etc/nginx/nginx.conf # nginx 설정 파일 volume 맵핑
restart: 'unless-stopped' # 내부에서 에러로 인해 container가 죽을 경우 restart
depends_on:
- prod
dev:
container_name: nestjs_api_dev
image: nestjs-api-dev:1.0.0
build:
context: .
target: development
dockerfile: ./Dockerfile
command: npm run start:dev #node dist/src/main #n
ports:
- 3001:3000
networks:
- nestjs-network
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
restart: unless-stopped
prod:
container_name: nestjs_api_prod
image: nestjs-api-prod:1.0.0
build:
context: .
target: production
dockerfile: ./Dockerfile
command: npm run start:prod
# ports:
# - 3000:3000
# - 9229:9229
expose:
- '3000' # 다른 컨테이너에게 3000번 포트 open
networks:
- nestjs-network
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
restart: unless-stopped
networks:
nestjs-network:```
Ok... I found the solution.
At the docker-compose.yaml, .:/usr/src/app should be removed from the volumes of the service "prod." Since the "dist" folder does not exist in the local machine, if the current local directory is mounted, then it shows Not found error. Guess I should study volume much deeper.

Why does VueJS not run production build?

I'm using a Docker-compose to initialize ExpressJS + VueJS and the RestFull API
This is docker compose:
version: '3'
services:
webserver:
build: ./webserver
ports:
- "3000:3000"
container_name: boleto_webserver
networks:
- boleto
volumes:
- ./webserver:/app/webserver
- /app/webserver/node_modules
website:
build: ./website
ports:
- "8080:8080"
container_name: boleto_website
networks:
- boleto
volumes:
- ./website:/app/website
- /app/webiste/node_modules
api:
build: ./api
ports:
- "3030:3030"
container_name: boleto_api
networks:
- boleto
volumes:
- ./api:/app/api
- /app/api/node_modules
networks:
boleto:
external: true
name: boleto
In DockerFile inside Website (VueJS) I run a production build:
FROM node:12
WORKDIR /app/website
COPY package*.json ./
COPY . /app/website
RUN npm install
COPY . .
EXPOSE 8080
CMD ["npm","run","build"]
Browsing localhost:3000 here is where the webserve is being launched I have this message:
Error: ENOENT: no such file or directory, stat '/app/website/build/index.html'
Analyzing website logs:
Note that the development build is not optimized.
To create a production build, run npm run build.
If I run this applications separately, all them works well! Throwing inside a docker compose this happens! Anyone can help me?
Updating
The webserver insists on run script dev, if I remove it, it does not compile
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "nodemon app.js",
"dev": "nodemon app.js"
},
FROM node:12
WORKDIR /app/webserver
COPY package*.json ./
COPY . /app/webserver
RUN npm install && npm install nodemon
EXPOSE 3000
CMD ["npm","run","serve"]

GitLab AutoDevops Environment Issues

So I am new to Gitlab Autodevops having switched from Travis and Github. The issue I am currently facing is that when I make a push and the pipeline kicks in, it doesn't see any of my list environment variables. I set production, and testing environment variables for mongodb and redis, but during the pipeline, it's trying to connect to localhost for both, totally ignoring the environment variables set in CI/CD settings. See pictures below:
Dockerfile
WORKDIR /app
COPY package*.json ./
RUN apk add --update alpine-sdk nodejs npm python
RUN LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH && export LD_LIBRARY_PATH && npm i
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
docker-compose.yml
version: "3.7"
services:
backend:
container_name: dash-loan
environment:
MONGODB_PRODUCTION_URI: ${MONGODB_PRODUCTION_URI}
MONGODB_TEST_URI: ${MONGODB_TEST_URI}
REDIS_PRODUCTION_URL: ${REDIS_PRODUCTION_URL}
REDIS_TEST_URL: ${REDIS_TEST_URL}
PM2_SECRET_KEY: ${PM2_SECRET_KEY}
PM2_PUBLIC_KEY: ${PM2_PUBLIC_KEY}
PM2_MACHINE_NAME: ${PM2_MACHINE_NAME}
PORT: ${PORT}
MODE_ENV: ${NODE_ENV}
restart: always
build: .
ports:
- "8080:3000"
links:
- mongodb
- redis
mongodb:
container_name: mongo
environment:
MONGO_INITDB_DATABASE: dashloan
MONGO_INITDB_ROOT_USERNAME: sampleUser
MONGO_INITDB_ROOT_PASSWORD: samplePassword
restart: always
image: mongo
ports:
- "27017-27019:27017-27019"
volumes:
- ./src/database/init-mongo.js:/docker-entrypoint-point.initdb.d/init-mongo.js:ro
- ./mongo-volume:/data/db
redis:
container_name: redis
restart: always
image: redis:5.0
ports:
- "6379:6379"
volumes:
mongo-volume:
.gitlab-ci.yml
image: node:latest
services:
- mongo:latest
- redis:latest
cache:
paths:
- node_modules/
job:
script:
- npm i
- npm test
I need help on how to make sure the test pipeline is using the environment variables I set; and not trying to connect to localhost which fails.
Error on gitlab pipeline
Variables in Gitlab
GKE which is running fine
You could use shell runner instead of docker runner and then just call docker-compose in before script.
cache:
paths:
- node_modules/
job:
before_script:
- docker-compose up -d
script:
- npm i
- npm test
after_script:
- docker-compose down

How to compose a docker-compose to run npm natively and mongo in a docker

I am trying to run node natively but run mongoDB in a container, just can't figure out the best way to do it.
Should run a command in the api dir and start npm?
I am trying to be able to deploy the whole application with a docker-compose up
Here are my files:
docker-compose.yml
/api
Dockerfile
package.json
/db
This is the docker-compose.yml
version: '3'
services:
api:
container_name: fl_api
command: cd api && npm start
ports:
- "3002:3002"
environment:
DB_PORT: "27017"
DB_HOST: mongo
PORT: "3002"
networks:
- api_net
mongo:
container_name : fl_mongodb
image: mongo:4.0
volumes:
- ./db/mong-vol:/data/db
networks:
- api_net
expose:
- "27017"
healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/zenbrain --quiet
interval: 5s
timeout: 5s
retries: 12
networks:
api_net:
driver: bridge
This is the api/Dockerfile
FROM node:6
WORKDIR /food-license-backend
COPY package.json /food-license-backend
RUN npm install
COPY . /food-license-backend
EXPOSE 3002
CMD ["npm", "run", "start"]

Resources