I’m not an expert with Gitlab CI/CD and Gitlab Runner. I tried many times but I cannot figure out why one of my pipelines is failing since I updated Snowpack, in particular the one where I use Docker. If I execute Docker locally in my machine everything works but not in the Gitlab pipeline.
This is my gitlab-ci.yml
# PAGES
gitlab-pages:
image: node:latest
stage: .pre
script:
- npm ci
- npm run build
- cp -r build/* public/
artifacts:
paths:
- public
only:
- master
# PREPARING FOR SERVER
variables:
TAG_LATEST: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:latest
gitlab-docker:
image: docker:latest
stage: build
services:
- docker:dind
script:
- docker build -t $TAG_LATEST .
…
Gilab Pages work pefectly but I get an error in the docker build -t $TAG_LATEST . with the npm run build
This is my Dockerfile
# Build
FROM node:latest as builder
WORKDIR /app-admin
COPY . .
COPY config/pre/.env .
RUN npm ci
RUN npm run build
This is the log error
Removing intermediate container c993aeab6bee
[78](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L78) ---> a52607c01b6b
[79](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L79)Step 6/10 : RUN npm run build
[80](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L80) ---> Running in baad4cd041e6
[81](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L81)> app-admin@1.0.0 build
[82](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L82)> snowpack build
[83](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L83)[21:07:03] [snowpack] ! building files...
[84](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L84)[21:07:03] [snowpack] (/_snowpack/pkg/import-map.json) Deprecated manual package import. Please use snowpack.getUrlForPackage() to create package URLs instead.
[85](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L85)[21:07:03] [snowpack] Package "import-mapon" not found. Have you installed it?
[86](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L86)[21:07:03] [snowpack] Error: Package "import-mapon" not found. Have you installed it?
[87](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L87) at Object.resolveEntrypoint (/app-admin/node_modules/snowpack/lib/index.js:43664:15)
[88](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L88) at Object.resolvePackageImport (/app-admin/node_modules/snowpack/lib/index.js:54611:34)
[89](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L89) at Object.loadUrl (/app-admin/node_modules/snowpack/lib/index.js:131391:53)
[90](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L90) at flushFileQueue (/app-admin/node_modules/snowpack/lib/index.js:131966:44)
[91](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L91) at async build (/app-admin/node_modules/snowpack/lib/index.js:131992:5)
[92](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L92) at async Object.command (/app-admin/node_modules/snowpack/lib/index.js:132080:9)
[93](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L93) at async cli (/app-admin/node_modules/snowpack/lib/index.js:132389:9)
[94](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L94)The command '/bin/sh -c npm run build' returned a non-zero code: 1
[95](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L95)Cleaning up file based variables00:03
[96](https://gitlab.com/app_main/app-admin/-/jobs/1173567591#L96)ERROR: Job failed: exit code 1
Runner: Pre Deployment Runner (#4361809)
Versions
gitlab-runner 13.9.0
docker:latest
node:latest
Snowpack 3.2.2
It works on my machine and on my server when I run docker build but on Gitlab only with Snowpack <= 3.0.x. I couldn’t find anything related with Snowpack, and the thing is that docker:latest and node:latest should be the same versions on Gitlab, so it should behave with Gitlab Runner like in my computer & server? or not? Why does it work also in Gitlab Pages?
I really don’t know what I am missing, if you need extra info/details let me know and I will be more than happy to help. Is someone having a similar issue? thanks a lot for your time and help!
Thank you so much @snim2 I saw that post 2 weeks ago and I’m still struggling with the issue. The point is that I don’t have anything similar in my snowpack.config.js and again it works everywhere except with Gilab Runner using Docker.
Thank you so much @balonik that package doesn’t exist, I couldn’t find it. Could be created during that pipeline?
Why does Snowpack works with Gitlab Pages but not when using Gitlab Runner + Docker?
Snowpack is not complaining with Gitlab Pages, neither locally in my machine with Docker or in my server.
I just copied it that part from a tutorial I don’t have much experience with Gitlab CI/CD. I removed that specific line and with previous Snowpack version keeps working but as soon as I update if crashes again, showing same error but now I have extra warnings.
Extra warnings:
Step 5/10 : RUN npm ci
[34](https://gitlab.com/app_main/app-admin/-/jobs/1178891417#L34) ---> Running in 14710f11f336
[35](https://gitlab.com/app_main/app-admin/-/jobs/1178891417#L35)npm WARN deprecated har-validator@5.1.5: this library is no longer supported
[36](https://gitlab.com/app_main/app-admin/-/jobs/1178891417#L36)npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
[37](https://gitlab.com/app_main/app-admin/-/jobs/1178891417#L37)added 532 packages, and audited 533 packages in 10s
You can use files between jobs using the artifacts keyword. Actually this might be your problem
By default, jobs in later stages automatically download all the artifacts created by jobs in earlier stages. In other words, your gitlab-docker job already has files in public directory which you created in gitlab-pages job. When you COPY . . you also copy the public directory. And this might be what snowpack doesn’t like.
You already built your application in the gitlab-pages job and placed it in public directory. And since you make it available to jobs in next stages (using the artifacts which is also used by Pages), you can use it directly in gitlab-docker job.
In your case just changing the Dockerfile to this.
FROM node:latest as builder
WORKDIR /app-admin
COPY ./public /app-admin/
COPY config/pre/.env /app-admin/
should be enough.
You can control artifact download behavior in jobs with dependencies keyword.
I cannot express with words how greatful I feel, you made my day! Awesome, directly to the point, now it works like a charm! You explained it so good, you should teach others. Thank you so much.
I owe you some beers, please enjoy the rest of the day!
ps: please, someone raise Peter’s salary