# For the testing stage you must include all those lines so the tests run and finish. If ng test doesnt have the flags that come after it, it will hang on that stage.
image: node:latest
before_script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
stages:
- production
production:
type: deploy
stage: production
image: ruby:latest
script:
- dpl --provider=heroku --app=$HEROKU_APP_PRODUCTION --api-key=$HEROKU_API_KEY
only:
- master
Good Evening,
I am trying to use my environment key that is set up in the environment file in Angular in my pipeline, but Gitlab does not know how to use it. process.env.(insert variable name) does not work. I have set the env variable in my gitlab pipeline dashboard. I am just not sure how to use that in my app. Any guidance is appreciated.
Thats quite a long answer, you need to list your config or job so we can trouble shoot. In short here are the main components to setup
First setup pipeline jobs like so, you should see your image in your dashboard
myTestjob:
stage: stage_a
image: node:12-alpine
tags:
- docker
script:
- node --version
Second, setup your dependencies
stages:
- install
install_dependencies:
stage: install
image: node:12-alpine
tags:
- docker
script:
- yarn install
- yarn ngcc --properties es2015 --create-ivy-entry-points
cache:
key:
files:
- yarn.lock
paths:
- node_modules
only:
refs:
- merge_requests
- master
changes:
- yarn.lock
remember that your cache key is invalidated whenever you make changes to yarn.lock
cache:
key:
files:
- yarn.lock
paths:
- node_modules
policy: pull
In your angular,json build your application job
{
"projects": {
"angular-app-example": {
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "artifacts/app"
}
}
}
}
}
}
Setup your env variable, gitlab has many
variables:
PROJECT_PATH: "$CI_PROJECT_DIR"
APP_OUTPUT_PATH: "$CI_PROJECT_DIR/artifacts/app"
build_app:
stage: build_and_test
image: node:12-alpine
tags:
- docker
script:
- yarn ng build --prod
after_script:
- cp $PROJECT_PATH/Dockerfile $APP_OUTPUT_PATH
artifacts:
name: "angular-app-pipeline"
paths:
- $APP_OUTPUT_PATH
cache:
key:
files:
- yarn.lock
paths:
- node_modules
policy: pull
here is a nice ref. on how to setup in more detail
UPDATE after user posted YML file to setup staging and production
cache:
paths:
- node_modules/
deploy_stage:
stage: deploy
environment: Stage
only:
- master
script:
- rm ./package-lock.json
- npm install
- ./node_modules/#angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/#angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/#angular/cli/bin/ng build --progress false --prod --base-href tykt-stage.surge.sh
- ./node_modules/.bin/surge -p dist/ --domain tykt-stage.surge.sh
deploy_production:
stage: deploy
environment: Production
only:
- tags
script:
- rm ./package-lock.json
- npm install
- ./node_modules/#angular/cli/bin/ng test --progress false --single-run=true --watch=false
- ./node_modules/#angular/cli/bin/ng e2e --progress false --watch=false
- ./node_modules/#angular/cli/bin/ng build --progress false --prod --base-href tykt.surge.sh
- ./node_modules/.bin/surge -p dist/ --domain tykt.surge.sh
You can use either section and update your domain it should build and push the CI CD
Related
I'm trying to deploy my project to Firebase Hosting using the following action:
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
deploy_to_firebase_hosting:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout#master
- name: Install Dependencies
run: npm install
- name: Build for production
run: npm run build-prod
- name: Deploy to Firebase
uses: w9jds/firebase-action#master
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
The actions gets failed on Build For Production step. My build-prod script does webpack -p --mode production.
This is the error message for this failure:
> project-name#1.0.0 build-prod /home/runner/work/project-name/project-name
> webpack -p --mode production
/home/runner/work/project-name/project-name/node_modules/webpack-cli/bin/cli.js:93
throw err;
^
TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
...
I've been researching about this error and I found out that people solve it by deleting node_modules before running the build. So I ran another action, without the npm install part.
It fails again on Build for production, but with a different, much reasonable error:
> webpack -p --mode production
webpack not installed
Install webpack to start bundling:
$ npm install --save-dev webpack
npm ERR! code ELIFECYCLE
npm ERR! errno 1
What's the correct way to build a production bundle in Github Actions?
Thanks!
I had the exact same issue when trying to use GitHub actions to build & deploy a production Docker container.
It turned out the issue on my side was as a result of Webpack not having access to any environment variables (which my Webpack config required) at the point of build which caused it to error out with the same error you received above.
To fix this I added the following line to my build command:
--env.NODE_ENV=production
E.g my final build command called by the container was then:
node --max_old_space_size=4096 ./node_modules/webpack/bin/webpack.js --env.NODE_ENV=production --progress --config webpack.prod.js
Hope this helps!
I'm using react/amplify stack. After publishing app, i realized that all code there is not minified, i'm able to open any component and see it's unminified source code. As i understood, amplify builds app based on it's amplify.yml file. I didn't change there anything and it looks like this:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: build
files:
- '**/*'
cache:
paths:
- node_modules/**/*
I can see a command there - 'npm run build' which i suppose should build app and then publish it as minified version. So why it hasn't happened?
npm run build is going to do whatever is configured in the scripts section of your package.json. Likely you'd want to configure environmental variables to indicate what type of build to do. Here is how the create-react-app project has chosen to do it:
...
"scripts": {
"build": "REACT_APP_ENV=development react-scripts build",
"build:development": "REACT_APP_ENV=development react-scripts build",
"build:production": "REACT_APP_ENV=production react-scripts build",
...
},
...
Using this pattern, you can either manually specify what type of build you want, or set the environment variable and just run npm run build.
Environmental variables in Amplify are configured under App Settings > Environmental Variables.
I am completely new to donejs and created the donejs app using yeoman, and then created a few components. For deploying the application, I ran "node build" and a dist folder was created, which contained a bundles folder and a steal.production.js file.
What is the way to deploy this dist folder over a nodejs server which basically serves the application and also, I dont want any watching in the console, it should basically just start serving over the port, so that the devops can run scripts after that.
build.js
var stealTools = require("steal-tools");
var buildPromise = stealTools.build({
config: __dirname + "/package.json!npm"
}, {
bundleAssets: true
});
From the dist folder :
λ ls
bundles/ steal.production.js
Scripts in my package.json file :
"scripts": {
"test": "testee test.html --browsers firefox --reporter Spec",
"start": "donejs grunt && done-serve --port 8080",
"grunt": "grunt",
"develop": "done-serve --develop --port 8080",
"build": "donejs grunt && donejs develop"
},
After running donejs start :
C:\Users\saljain\Documents\work\statusui\status\status (master)
λ donejs start
> status#0.0.0 start C:\Users\saljain\Documents\work\statusui\status\status
> donejs grunt && done-serve --port 8080
> status#0.0.0 grunt C:\Users\saljain\Documents\work\statusui\status\status
> grunt
Running "less:development" (less) task
>> 1 stylesheet created.
Done.
done-serve starting on http://localhost:8080
It is serving on 8080 but the console is blocked on this, devops team is saying that the console should not be blocked so that they can run scripts after starting the server.
I can see a start script, so try out donejs start if everything else is in order.
Here's some more options as well according to their docs:
To test the production build: NODE_ENV=production donejs start
https://donejs.com/Guide.html#production-build
I have an API developed in NodeJS and have successfully set up continuous integration via a .gitlab-ci.yml file. The next stage is to set up continuous deployment to Heroku if all tests pass on the master branch.
There are plenty of tutorials covering the deployment of Ruby and Python apps but nothing on NodeJS. Currently my .gitlab-ci.yml file looks like this:
image: node:latest
job1:
script: "ls -l"
test:
script: "npm install;npm test"
production:
type: deploy
script:
- npm install
- npm start
- gem install dpl
- dpl --provider=heroku --app=my-first-nodejs --api-key=XXXXXXXXXX
only:
- master
The Ruby and Python tutorials use the dpl tool to deploy but how can I start the NodeJS script on the server once deployed?
After adding the production section and pushing it the tests run and pass but the deploy stage gets stuck on pending. The console is blank. Has anyone set up a successful CD script for NodeJS?
you could use a much more simple YAML script where you can define the stages for the CI (to run test before production deploy) you can then use a different image at the Heroku deploy stage. So for a node app you define the default image as node:latest. Then for the production deployment using dpl you can use the ruby image.
image: node:latest
stages:
- job1
- test
- production
job1:
stage: job1
script: "ls -l"
test:
stage: test
script:
- npm install
- npm test
artifacts:
paths:
- dist/
production:
type: deploy
stage: production
image: ruby:latest
script:
- apt-get update -qy
- apt-get install -y ruby-dev
- gem install dpl
- dpl --provider=heroku --app=my-first-nodejs --api-key=XXXXXXXXXX
only:
- master
Well, this won't be the longest answer ever, but this may help you.
Here's the content if it ever disappear:
image: node:argon
before_script:
- apt-get -qq update
- apt-get -qq install -y python2.7 python2.7-dev build-essential make gcc g++ libicu-dev
- npm -g install npm --silent
- "echo -e \"export default {CLIENT_ID: '$CLIENT_ID'}\" > app/scripts/settings.js"
- npm set progress=false
- npm install --silent
stages:
- test
- build
- clean_up
run_tests:
stage: test
script:
- npm test
build_and_deploy_prod:
stage: build
script:
- npm run build
- mkdir dist/build
- tar czfC dist/build/latest.tar.gz dist/$CI_BUILD_REF_NAME/ .
- tar czfC dist/build/$CI_BUILD_REF.tar.gz dist/$CI_BUILD_REF_NAME/ .
- apt-get install -yqq ruby ruby-dev
- gem install dpl
- dpl --skip_cleanup --provider=s3 --region=eu-west-1 --access-key-id=$AWS_ACCESS_KEY --secret-access-key=$AWS_SECRET_KEY --bucket=$AWS_BUCKET --local-dir=dist/build/ --upload-dir=$CI_BUILD_REF_NAME
artifacts:
paths:
- dist/$CI_BUILD_REF_NAME/
only:
- master
- develop
clean_up_job:
stage: clean_up
script:
- rm -rf node_modules
- rm -rf ~/.node-gyp
when: on_failure
A well-explained article for Continuous Deployment of a NodeJS using GitLab :
LINK
Currently I have Typescript module with ./src dir in it
And travic-ci
language: node_js
node_js:
- 5.1.0
install:
- npm install
- npm install -g mocha
- npm install -g gulp
- npm install -g tsd
- tsd rate
- tsd install
script: gulp
after_success: npm test
deploy:
provider: npm
email: secret
api_key:
secure: secret
Gulp task generates files in to "./build" dir
The problem is that when it tries to deploy
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# build/
#
nothing added to commit but untracked files present (use "git add" to track)
So it force me to build project locally and add it to github, and makes using of travis-ci as useless step
Just resolved this problem with this steps:
1: Add ./build dir to .gitignore file
build
typings
test/**/*.js
test/**/*.map
2: Create .npmignore to omit .gitignore rules (and I also put .src dir in it)
src
test
typings