Hello my build script isn't creating a build script for reason I do not know, the Packjson has the correct script which is
"build": "npm run silentrenew && react-scripts --max_old_space_size=8192 build",
I have double checked my YML file and all the tags
version: '1.0.{build}'
image: Ubuntu
init:
- cmd: set NODE_OPTIONS=--max-old-space-size=8192
environment:
REACT_APP_VSA_URL: >-
https://xzc-e-n-vsa0000-d-api-02.xzc-e-n-snt-06-ut-ase-01.p.azurewebsites.net
REACT_APP_NOTIFICATIONS_API_SECRET: d8015bf6cab64573b2d7c17bac94bed4
REACT_APP_EVENT_LOG_SECRET: 3431cec7ecbb42bba1957934c751f02d
install:
- cmd: npm ci --ignore-scripts
build_script:
- cmd: |-
npm --no-git-tag-version version "%APPVEYOR_BUILD_VERSION%"
npm run build
test_script:
- cmd: 'npm run test:ci'
artifacts:
- path: ./build
name: dpe
deploy:
- provider: Environment
name: dpe-dev
'on':
branch:
- internal
- tablet
on_finish:
- pwsh: >-
# upload results to AppVeyor
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)",
(Resolve-Path .\coverage\junit\junit.xml))
# upload coverage results to CodeCov
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
bash codecov.sh -s "./coverage/jest/"
This is the exact message I'm getting in AppVeyor, since the build isn't creating it isn't running the test and saying it was successful.
For Linux builds the prefix must be sh: or no prefix at all:
build_script:
- sh: |-
npm --no-git-tag-version version "$APPVEYOR_BUILD_VERSION"
npm run build
Related
I am trying run reach a React application inside Circleci, so it can be reached by Cypress e2e. First I tried running the app with the Webpack web server, but the issue is the same.
When Cypress runs the tests, it cannot react to the instance where the React is being served from, so I am trying to use http-server instead.
This is what I have at the moment:
version: 2.1
jobs:
cypress:
working_directory: ~/project
docker:
- image: cypress/base:18.12.1
environment:
CYPRESS_baseUrl: http://127.0.0.1:3000
steps:
- checkout:
path: ~/project
- run:
name: Install dependencies
command: npm ci --ignore-scripts
- run:
name: Build
command: npm run build
- run:
name: Install http-server
command: npm install -g http-server
- run:
name: Serve React app
command: |
http-server ./dist/ -a 127.0.0.1 -p 3000 &
# - run:
# name: Wait for server to start
# command: npx wait-on http-get:http://127.0.0.1:3000
- run:
name: cypress install
command: npx cypress install
- run:
name: Run cypress tests
command: npx cypress run
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
e2e_test:
jobs:
- cypress
When I run http-server ./dist/ -a 127.0.0.1 -p 3000 in the foreground, I can see the server is starting:
Starting up http-server, serving ./dist/
http-server version: 14.1.1
http-server settings:
CORS: disabled
Cache: 3600 seconds
Connection Timeout: 120 seconds
Directory Listings: visible
AutoIndex: visible
Serve GZIP Files: false
Serve Brotli Files: false
Default File Extension: none
Available on:
http://127.0.0.1:3000
Hit CTRL-C to stop the server
When I run it in the background and the script reaches the tests, I get this:
[667:0213/085129.291037:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
Cypress could not verify that this server is running:
> http://127.0.0.1:3000
We are verifying this server because it has been configured as your baseUrl.
Cypress automatically waits until your server is accessible before running tests.
We will try connecting to it 3 more times...
We will try connecting to it 2 more times...
We will try connecting to it 1 more time...
Cypress failed to verify that your server is running.
Please start this server and then run Cypress again.
Exited with code exit status 1
CircleCI received exit code 1
I tried waiting for the server with: npx wait-on http-get:http://127.0.0.1:3000 but it just stays waiting forever.
I had the same issue when I ran the React app with the Webpack server. The app and the tests run without issues in my dev env.
Any help would be greatly appreciated.
For anyone else facing this issue, I solved it by running the server and the test under the same process. I did not know that every command runs in a separate process as described in this post. The code changed to this thanks to ChatGpt suggesting the use of the nohup command, which runs the specified command with no hang-up signals so that it continues to run even if the terminal session is closed:
jobs:
cypress:
working_directory: ~/project
docker:
- image: cypress/base:18.12.1
environment:
CYPRESS_baseUrl: http://127.0.0.1:3000
steps:
- checkout:
path: ~/project
- run:
name: Install dependencies
command: npm ci --ignore-scripts
- run:
name: Build
command: npm run build
- run:
name: Install http-server
command: npm install -g http-server
- run:
name: cypress install
command: npx cypress install
- run:
name: Serve React app and run test
command: |
nohup http-server ./dist/ -a 127.0.0.1 -p 3000 > /dev/null 2>&1 &
npx wait-on http://127.0.0.1:3000 && npx cypress run
I'm using gitlab-ci and gitlab runner to deploy my React app to my server.
Here is my code:
image: node:alpine
variables:
PUBLIC_URL: https://example.com
stages:
- build
- deploy
build:
stage: build
tags:
- some-tag
- another-tag
script:
- echo "Building deploy package"
- pwd
- npm install
- mv .env.example .env
- echo ".env file changed!"
- CI='' npm run build
- echo "Build successful"
- ls
artifacts:
expire_in: 1 hour
paths:
- build
only:
- master
deploy_production:
stage: deploy
tags:
- some-tag
- another-tag
script:
- echo "Current Directory:"
- pwd
- ls
- echo "Deploying to server"
- cp -rv ./build/* /dir/path-in-my-server/
- echo "Deployed"
artifacts:
expire_in: 1 hour
paths:
- build
environment:
name: production
url: https://example.com
only:
- master
Every steps works well, but cp -rv ./build/* /dir/path-in-my-server/ is not working. It giving this error:
cp: can't create '/dir/path-in-my-server/asset-manifest.json': No such file or directory
cp: can't create '/dir/path-in-my-server/favicon.ico': No such file or directory
cp: can't create '/dir/path-in-my-server/index.html': No such file or directory
cp: can't create '/dir/path-in-my-server/manifest.json': No such file or directory
cp: can't create directory '/dir/path-in-my-server/static': No such file or directory
Cleaning up file based variables
00:03
ERROR: Job failed: exit code 1
What am I missing?
I fixed this issue by using $PWD env variable instead of relative paths like ./. GitLab seems to have a problem with relative paths in cp and mv commands.
script:
- cp -rv ${PWD}/some-directory/* /your-dest-dir/
PROBLEM
Hey, I have not used Docker much - I am trying to run my Jest tests through the Dockerfile. However, I'm getting this error when trying to build image:
ERROR
Step 13/16 : RUN if [ "$runTests" = "True" ]; then RUN npm test; fi
---> Running in ccdb3f89fb79
/bin/sh: RUN: not found
Dockerfile
FROM node:10-alpine as builder
ARG TOKEN
WORKDIR /app
ARG runTests
COPY .npmrc-pipeline .npmrc
COPY package*.json ./
RUN npm install
COPY . .
RUN rm -f .npmrc
ENV PORT=2000
ENV NODE_ENV=production
RUN if [ "$runTests" = "True" ]; then \
RUN npm test; fi
RUN npm run build
EXPOSE 2000
CMD ["npm", "start"]
The command I am using to build the image is this, and the idea is to be able to run the tests only when runTests=True.
docker build -t d-image --build-arg runTests="True" --build-arg "MY TOOOOOKEN"
Is this possible to do by just using the Dockerfile? Or is it necessary to use docker-compose as well?
The conditional statement seems to work good.
Not posssible to have two CMD commands
I have tried this as a workaround (but it did not work):
Dockerfile
FROM node:10-alpine as builder
ARG TOKEN
WORKDIR /app
ARG runTests
COPY .npmrc-pipeline .npmrc
COPY package*.json ./
RUN npm install
COPY . .
RUN rm -f .npmrc
ENV PORT=3000
ENV NODE_ENV=production
RUN npm run build
EXPOSE 3000
CMD if [ "$runTests" = "True" ]; then \
CMD ["npm", "test"] && ["npm", "start"] ;fi
Now I'm not getting any output from the test, but it looks to be successful.
PROGRESS
I have made some progress and the tests are actually running when I'm building the image. I also decided to use the RUN command for running the tests, so that they run on the build step.
Dockerfile:
FROM node:10-alpine as builder
ARG TOKEN
WORKDIR /app
COPY .npmrc-pipeline .npmrc
COPY package*.json ./
RUN npm install
COPY . .
RUN rm -f .npmrc
ENV PORT=3000
ENV NODE_ENV=production
RUN npm run build
RUN npm test
EXPOSE 3000
Error:
FAIL src/pages/errorpage/tests/accessroles.test.jsx
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
It seems to me that the docker build process does not use the jest:{...} configurations in my package.json, even though it is copied and installed in the Dockerfile Any ideas?
RUN and CMD aren't commands, they're instructions to tell Docker what do when building your container. So e.g.:
RUN if [ "$runTests" = "True" ]; then \
RUN npm test; fi
doesn't make sense, RUN <command> runs a shell command but RUN isn't defined in the shell, it should just be:
ARG runTests # you need to define the argument too
RUN if [ "$runTests" = "True" ]; then \
npm test; fi
The cleaner way to do this is to set up npm as the entrypoint, and start as the specific command:
ENTRYPOINT [ "npm" ]
CMD [ "start" ]
This allows you to build the container normally, it doesn't require any build arguments, then run an NPM script other than start in the container, e.g. to run npm test:
docker run <image> test
However, note that this means all of the dev dependencies need to be in the container. It looks (from ENV NODE_ENV=production) like you intend this to be a production build, so you shouldn't be running the tests in the container at all. Also despite having as builder this isn't really a multi-stage build. The idiomatic script for this would be something like:
# stage 1: copy the source and build the app
FROM node:10-alpine as builder
ARG TOKEN
WORKDIR /app
COPY .npmrc-pipeline .npmrc
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# stage 2: copy the output and run it in production
FROM node:10-alpine
WORKDIR /app
ENV PORT=3000
ENV NODE_ENV=production
COPY --from=builder /app/package*.json ./
RUN npm ci
COPY --from=builder /* your build output */
EXPOSE 3000
ENTRYPOINT [ "npm" ]
CMD [ "start" ]
See e.g. this Dockerfile I put together for a full-stack React/Express app.
A couple things on this:
2 commands are possible (but NOT recommended) , as I did here: https://hub.docker.com/repository/docker/djangofan/mountebank-with-ui-node
Also, I wouldn't recommend that your tests run while building your container image. Instead, build the container image so that it maps a folder to the location of your test files. Then, include your "temporary test image" in your compose file.
version: '3.4'
services:
service-api:
container_name: service-api
build:
context: .
dockerfile: Dockerfile-apibase
ports:
- "8083:8083"
e2e-tests:
container_name: e2e-tests
build:
context: .
dockerfile: Dockerfile-testbase
command: bash -c "wait-for-it.sh service-api:8083 && gradle -q clean test -Dorg.gradle.project.buildDir=/usr/src/example"
Then execute it like so to get a 0 or 1 exit code:
docker-compose up --exit-code-from e2e-tests
After running that, the service will remain running but the tests will shutdown when finished.
Hopefully that makes sense even though the example I gave is not exactly like your situation. Here is a LINK to my example from above, which you can try yourself. It should work similarly for Jest tests.
I want to build and deploy my react app from my master branch I have managed to automate build but unable to transfer it into my server find my pipeline code below, I receive below error
pipelines:
default:
- step:
name: Build Title
script:
- npm install
- npm run build
- mkdir packaged
- tar -czvf packaged/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C build .
artifacts:
- packaged/**
- step:
name: Deploy to Web
image: alpine
trigger: manual
deployment: production
script:
- mkdir upload
- tar -xf packaged/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C upload
- apk update && apk add openssh rsync
- rsync -a -e "ssh -o StrictHostKeyChecking=no" --delete upload/ $USERNAME#$SERVER:html/temp/react-${BITBUCKET_BUILD_NUMBER}
- ssh -o StrictHostKeyChecking=no $USERNAME#$SERVER "rm -r html/www"
- ssh -o StrictHostKeyChecking=no $USERNAME#$SERVER "mv 'html/temp/react-${BITBUCKET_BUILD_NUMBER}' 'var/www/html/deploy'"
- ssh -o StrictHostKeyChecking=no $USERNAME#$SERVER "chmod -R u+rwX,go+rX,go-w html/www"
Error Log
+ rsync -a -e "ssh -o StrictHostKeyChecking=no" --delete upload/ $USERNAME#$SERVER:html/temp/react-${BITBUCKET_BUILD_NUMBER}
load pubkey "/opt/atlassian/pipelines/agent/ssh/id_rsa": invalid format
rsync: mkdir "/$USERNAME/html/temp/react-15" failed: No such file or directory (2)
rsync error: error in file IO (code 11) at main.c(675) [Receiver=3.1.2]
I noticed. this to happen only on Alpine-based images. For example, Debian images work fine. It also happens on Buddy, not just on Bitbucket. I expect this is upstream Alpine bug/issue.
I was using that same script as well, below is what ended up working for me after a lot of banging my head against the screen, updating the image and adding upload artifacts seemed to be the kicker.
default:
- step:
name: Build React Project
script:
- npm install
- npm run-script build
- mkdir packaged
- tar -czvf packaged/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C build .
artifacts:
- packaged/**
- step:
name: Deploy to Web
image: atlassian/default-image:latest
trigger: manual
deployment: production
script:
- mkdir upload
- tar -xf packaged/package-${BITBUCKET_BUILD_NUMBER}.tar.gz -C upload
- rsync -a --delete upload/ $USERNAME#$SERVER:/home/temp/react-${BITBUCKET_BUILD_NUMBER}
- ssh $USERNAME#$SERVER "rm -r /home/www"
- ssh $USERNAME#$SERVER "mv '/home/temp/react-${BITBUCKET_BUILD_NUMBER}' '/home/www'"
- ssh $USERNAME#$SERVER "chmod -R u +rwX,go+rX,go-w /home/www"
artifacts:
- upload/**
I am trying to set up bitbucket-pipelines.yml file to do the build and then deploy react project. There is my code below.
image: node:10.15.1
pipelines:
default: # Pipelines that are triggered manually via the Bitbucket GUI
- step:
name: Build
script:
- yarn
- yarn build
- step:
name: Deploy
script:
- apt-get update
- apt-get install ncftp
- ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/*
- echo Finished uploading /build files to $FTP_HOST$FTP_SITE_ROOT
I am getting the result:
+ ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/*
could not stat build/*: No such file or directory.
ncftpput build/*: no valid files were specified.
It says that there is no build file or directory. but yarn build is actually build folder creates: react-scripts build
From Atlassian documentation
Key concepts
A pipeline is made up of a set of steps.
Each step in your pipeline runs a separate Docker container. If you
want, you can use different types of container for each step, by
selecting different images
So, when you try to send it in Deploy Step it's not there because you built it in another container.
To pass files between steps you have to use Artifacts
image: node:10.15.1
pipelines:
default: # Pipelines that are triggered manually via the Bitbucket GUI
- step:
name: Build
script:
- yarn
- yarn build
artifacts: # defining build/ as an artifact
- build/**
- step:
name: Deploy
script:
- apt-get update
- apt-get install ncftp
- ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/*
- echo Finished uploading /build files to $FTP_HOST$FTP_SITE_ROOT