How can I debug dist/ is not generating on Docker Cloud Build? - docker

I’m trying to automate build on dockercloud to build a docker container for my front-end.
I have
web.dockerfile
### STAGE 1: Build ###
FROM node:9.3.0-alpine as builder
COPY package.json ./
RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
RUN npm i
RUN mkdir /web
RUN cp -R ./node_modules ./web
WORKDIR /web
COPY . .
## Build the angular app in production mode and store the artifacts in dist folder
RUN $(npm bin)/ng build --prod --build-optimizer
### STAGE 2: Setup ###
FROM nginx:1.13.8-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY site.conf /etc/nginx/conf.d/default.conf
RUN rm -rf /usr/share/nginx/html/*
COPY dist /usr/share/nginx/html/
RUN touch /var/run/nginx.pid && \
chown -R nginx:nginx /var/run/nginx.pid && \
chown -R nginx:nginx /var/cache/nginx && \
chown -R nginx:nginx /usr/share/nginx/html
USER nginx
as you see I already did this line :
RUN $(npm bin)/ng build --prod --build-optimizer
Which it should generate the dist/ folder for me.
I got
This long logs in my docker-cloud
What I don't understand is, it is working fine, when I used that Dockerfile locally.
Should I look into my webpack settings or my Dockerfile syntax ?

Use the --from argument to COPY to set the source location to a previous build stage.
COPY --from=builder /web/dist /usr/share/nginx/html/
For your local build you probably have a dist/ folder for your local development which is then included in the build context sent to Docker. The local copy is what ends up in the image.

Related

Docker build is using cache for COPY command even if my files have changed

I have a Dockerfile that is as follow:
FROM node:14-alpine as frontend-builder
WORKDIR /app/frontend
COPY ./frontend .
ENV PATH ./node_modules/.bin/:$PATH
RUN set -ex; \
yarn install --frozen-lockfile --production; \
yarn cache clean; \
yarn run build
CMD ["tail", "-f", "/dev/null"]
I have changed one file in frontend folder and re-run the build and docker is using the cache...I know i can force to build with --no-cache but how can i tweak docker so it detects changes in my files instead of no-cache option ?

docker buildx not copying files when in production

I am having an issue where the docker buildx tool doesn't properly copy files to the production container. For example:
FROM --platform=$BUILDPLATFORM node:16.14.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY yarn.lock ./
RUN apk update && apk add python3 g++ make && rm -rf /var/cache/apk/*
RUN yarn install
COPY . ./
RUN yarn run build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html/
COPY ./nginx/nginx.conf /etc/nginx/conf.d/default.conf
# Default port exposure
EXPOSE 80
# Copy .env file and shell script to container
COPY ./env.sh /usr/share/nginx/html/env.sh
# Start Nginx server
CMD ["/bin/sh", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
All of the files from build will copy properly. However, the nginx.conf and env.sh will report as not found. Any ideas?
P.S: This seems to be an issue with nginx:alpine. No clue

Dockerfile for Meteor 2.2 proyect

I have been trying for almost 3 weeks to build and run a meteor app (bundle) using Docker, I have tried all the majors recommendations in Meteor forums, Stackoverflow and official documentarion with no success, first I tried to make the bundle and put inside the docker but have awful results, then I realized what I need to do is to make the bundle inside the docker and use a multistage Dockerfile, here is the one I am using right now:
FROM chneau/meteor:alpine as meteor
USER 0
RUN mkdir -p /build /app
RUN chown 1000 -R /build /app
WORKDIR /app
COPY --chown=1000:1000 ./app .
COPY --chown=1000:1000 ./app/packages.json ./packages/
RUN rm -rf node_modules/*
RUN rm -rf .meteor/local/*
USER 1000
RUN meteor update --packages-only
RUN meteor npm ci
RUN meteor build --architecture=os.linux.x86_64 --directory /build
FROM node:lts-alpine as mid
USER 0
RUN apk add --no-cache python make g++
RUN mkdir -p /app
RUN chown 1000 -R /app
WORKDIR /app
COPY --chown=1000:1000 --from=meteor /build/bundle .
USER 1000
WORKDIR /app/programs/server
RUN rm -rf node_modules
RUN rm -f package-lock.json
RUN npm i
FROM node:lts-alpine
USER 0
ENV TZ=America/Santiago
RUN apk add -U --no-cache tzdata && cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /app
RUN chown 1000 -R /app
WORKDIR /app
COPY --chown=1000:1000 --from=mid /app .
USER 1000
ENV LC_ALL=C.UTF-8
ENV ROOT_URL=http://localhost/
ENV MONGO_URL=mongodb://locahost:21027/meteor
ENV PORT=3000
EXPOSE 3000
ENTRYPOINT [ "/usr/local/bin/node", "/app/main.js" ]
if I build with docker build -t my-image:v1 . then run my app with docker run -d --env-file .dockerenv --publish 0.0.0.0:3000:3000 --name my-bundle my-image:v1 it exposes port:3000 but when I try to navigate with my browser to http://127.0.0.1:3000 it redirects to https://localhost, if i do docker exec -u 0 -it my-bundle sh, then apk add curl, then curl 127.0.0.1:3000 I can see the meteor app running inside docker.
Has anyone had this issue before, maybe I am missing some configuration? my bundle also works fine outside docker with node main.js in the bundle folder and can visit http://127.0.0.1:3000 with my browser.
Thanks in advance

Yarn test with docker inside github actions does not finish ever

I've a react app that is build with docker. And now I've tests on it, but the step yarn test never finish inside a github action.
This is my dockerfile:
FROM node:alpine as build
WORKDIR /app
RUN apk update && apk add jq
COPY . /app
ENV PATH /app/node_modules/.bin:$PATH
RUN yarn --silent
RUN yarn lint
RUN yarn test
RUN yarn build
FROM nginx:alpine as nginx
RUN apk add --no-cache certbot
COPY nginx/renew /etc/periodic/daily/renew
RUN chmod +x /etc/periodic/daily/renew
RUN mkdir /var/lib/certbot
VOLUME /var/log/nginx
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 80
EXPOSE 443
WORKDIR /usr/share/nginx/html
COPY ./env.sh .
COPY .env .
RUN apk add --no-cache bash
RUN chmod +x env.sh
CMD ["/bin/bash", "-c", "/usr/share/nginx/html/env.sh && nginx -g \"daemon off;\""]
Before add the line run yarn test everuthing works fine running the build in gh action, but after this is what appears:
Test Suites: 3 passed, 3 total
Tests: 10 passed, 10 total
Snapshots: 1 passed, 1 total
Time: 15.335s
Ran all test suites.
Error: The operation was canceled.
And gets there for almost 6 hours and the github stops the job by himself.
Any idea?

Docker, link container's files to host

I have a React App built with Docker :
FROM node:latest
WORKDIR /home/node/app
# Build
COPY package*.json ./
COPY src ./src
COPY public ./public
COPY .env* ./
RUN npm install
RUN npm run build
# Remove build material
RUN rm -f package.json
RUN rm -f package-lock.json
RUN rm -rf src
RUN rm -rf public
RUN rm -f .env
RUN rm -f .env.local
# Update host
CMD rm -rf /home/node/app/www/*;cp build/* /home/node/app/www
I'm building this image through a Gitlab CI / CD pipeline and launching it on my remote host with docker-compose :
version: '3'
services:
app:
image: registry.gitlab.com/myproject/www:production
volumes:
- /var/www:/home/node/app/www
I have Nginx running on my remote host that serves /var/www on port 80.
What I would like to do is my container to be bind to /var/www
ie: Each time I'm building and launching my image, /var/www gets updated by it.
My setup kinda work but I ran into issues, it doesn't refresh all the time for whatever reason.
Is there any better way to do so ?

Resources