I use simple demo react app project and dcpkerize it .But Travic CI think that its ruby project and install ruby dependencies every commit. Why so?
travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t axixa/docker-react -f Dockerfile.dev .
script:
- docker run axixa/docker-react npm run test -- --coverage
test project linkg https://github.com/ahvahsky2008/docker-react
Use language: generic at the top of your .travis.yml file.
And you do not need services: [docker] and probably not sudo: required.
This is how I am using it to test more complex apps:
# .travis.yml
language: generic
script:
- docker login -u $DOCKER_USER -p $DOCKER_PASS
- docker-compose build
- docker-compose run test
Seems like docker and docker-compose are a part of the base travis image.
Related
I'm new to Gitlab, newman and docker, and I'm sort of in a crash course on how to integrate everything together.
On my desktop (Windows OS), I've installed newman, and I have managed to run "newman run [postman collections]" via windows commandline.
What i ultimately want to do is to do run a newman command in Gitlab.
In the .gitlab-ci, I have this:
stages:
- test
Test_A:
stage: test
image: postman/newman
script:
- newman run Collection1.json
A few questions come to mind:
Do I need to also run the "npm install -g newman" command in the .gitlab-ci file?
If not, how does Gitlab know the syntax of a newman command?
Example: newman run
Do I need to specify in my .gitlab-ci file a command for docker?
Example: docker pull postman/newman
Update#2
stages:
- test
before_script:
- npm install -g newman
- npm install -g npm
Test_A:
stage: test
script:
- newman run Collection1.json
The first thing you have to identify is how your GitLab pipelines are executed.
My personal choice is to use Docker-based runner.
If you're using a GitLab docker-runner to run your pipeline then you just have to define your container image in the .gitlab-ci.yml file.
Here's a tested (on GitLab.com) version of pipeline yml
stages:
- test
run_postman_tests:
stage: test
image:
name: postman/newman
entrypoint: [""] #This overrides the default entrypoint for this image.
script:
- newman run postman_collection.json
I have a gitlab CI file that is building projects like this:
image: 'docker/compose:1.25.1-rc1'
services:
- 'docker:dind'
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- deploy
buildCode:
stage: build
except:
- deploy
script:
- docker build -t dataserver -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest -f dockerfile .
deployCode:
stage: deploy
only:
- deploy
script:
- docker build -t dataserver -t ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest -f dockerfile .
- docker login registry.gitlab.com -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}:latest
- docker network create network && echo 'creating network'
- docker-compose -f docker-compose.yml pull
- docker-compose -f docker-compose.yml rm -f -s
- docker-compose -f docker-compose.yml up -d
The idea is to use docker/compose:1.25.1-rc1 to bring a docker-compose environment and build the files.
The docker file itself is calling for this image to build
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
and then uses this image for runtime:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as final
so .net 3.1 should be installed.
however, when I run the app, I get this:
(I can't do a text capture, so this is a screenshot)
Which means that .net 3.1 is not installed and I can't figure out the problem.
If I compile the app for 3.0, with the same CI setup, it runs.
Try force a docker image pull of the images before build yours.
Seems your aspnet:3.1
Just had the 3.1.0-preview version when you pulled It.
The 3.1 tag aims always the last 3.1.xxx version.
Before release was the preview.. now is 3.1.0... in Future Will be 3.1.x.
If you already has pulled the image with the tag 3.1 your build will used the met image. And that may not be the current 3.1 in remote repository. If you pull It the hash is verified and will update the image If needed
I just got into the (wonderful) world of CI/CD and have working pipelines. They are not optimal, though.
The application is a dockerized website:
the source needs to be compiled by webpack and end up in dist
this dist directory is copied to a docker container
which is then remotely built and deployed
My current setup is quite naïve (I added some comments to show why I believe the various elements are needed/useful):
# I start with a small image
image: alpine
# before the job I need to have npm and docker
# the problem: I need one in one job, and the second one in the other
# I do not need both on both jobs but do not see how to split them
before_script:
- apk add --update npm
- apk add docker
- npm install
- npm install webpack -g
stages:
- create_dist
- build_container
- stop_container
- deploy_container
# the dist directory is preserved for the other job which will make use of it
create_dist:
stage: create_dist
script: npm run build
artifacts:
paths:
- dist
# the following three jobs are remote and need to be daisy chained
build_container:
stage: build_container
script: docker -H tcp://eu13:51515 build -t widgets-sentinels .
stop_container:
stage: stop_container
script: docker -H tcp://eu13:51515 stop widgets-sentinels
allow_failure: true
deploy_container:
stage: deploy_container
script: docker -H tcp://eu13:51515 run --rm -p 8880:8888 --name widgets-sentinels -d widgets-sentinels
This setups works bit npm and docker are installed in both jobs. This is not needed and slows down the deployment. Is there a way to state that such and such packages need to be added for specific jobs (and not globally to all of them)?
To make it clear: this is not a show stopper (and in reality not likely to be an issue at all) but I fear that my approach to such a job automation is incorrect.
You don't necessarily need to use the same image for all jobs. Let me show you one of our pipelines (partially) which does a similar thing, just with composer for php instead of npm:
cache:
paths:
- vendor/
build:composer:
image: registry.example.com/base-images/php-composer:latest # use our custom base image where only composer is installed on to build the dependencies)
stage: build dependencies
script:
- php composer.phar install --no-scripts
artifacts:
paths:
- vendor/
only:
changes:
- composer.{json,lock,phar} # build vendor folder only, when relevant files change, otherwise use cached folder form s3 bucket (configured in runner config)
build:api:
image: docker:18 # use docker image to build the actual application image
stage: build api
dependencies:
- build:composer # reference dependency dir
script:
- docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
- docker build -t $CI_REGISTRY_IMAGE:latest.
- docker push $CI_REGISTRY_IMAGE:latest
The composer base image contains all necessary packages to run composer, so in your case you'd create a base image for npm:
FROM alpine:latest
RUN apk add --update npm
Then, use this image in your create_dist stage and use image: docker:latest as image in the other stages.
As well as referncing different images for different jobs you may also try gitlab anchors which provides reusable templates for the jobs:
.install-npm-template: &npm-template
before_script:
- apk add --update npm
- npm install
- npm install webpack -g
.install-docker-template: &docker-template
before_script:
- apk add docker
create_dist:
<<: *npm-template
stage: create_dist
script: npm run build
...
deploy_container:
<<: *docker-template
stage: deploy_container
...
Try multistage builder, you can intermediate temporary images and copy generated content final docker image. Also, npm should be part on docker image, create one npm image and use in final docker image as builder image.
I'm trying to setup a basic pipeline in Gitlab that does the following:
Run tests command, compile the client and deploy the application using docker-compose.
The problem comes when I'm trying to use npm install.
My .gitlab-ci.yml file looks like:
# This file is a template, and might need editing before it works on your
project.
# Official docker image.
image: docker:latest
services:
- docker:dind
stages:
- test
- build
- deploy
build:
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
test:
stage: test
only:
- develop
- production
script:
- echo run tests in this section
step-deploy-production:
stage: deploy
only:
- production
script:
- docker-compose up -d --build
environment: production
when: manual
And the error is:
Skipping Git submodules setup
$ cd packages/public/client/
$ npm install --only=production
bash: line 69: npm: command not found
ERROR: Job failed: exit status 1
I'm using the last docker image, so, I'm wondering whether I can define a new service on my build stage or should I use a different image for the whole process?
Thanks
A new service will not help you, you'll need to use a different image.
You can use a node image just for your build-stage like this:
build:
image: node:8
stage: build
script:
- cd packages/public/client/
- npm install --only=production
- npm run build
Related, but not duplicated: Docker - docker-compose 'version' doesn't have any configuration options
I am currently using a v2 docker-compose.yml with the following circle.yml:
machine:
services:
- docker
test:
post:
- docker build --rm=false -t zurfyx/repo:$CIRCLE_SHA1 .
- docker-compose run web npm test
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
- docker push zurfyx/repo:$CIRCLE_SHA1
CircleCI gives the following output:
docker-compose run web npm test
ERROR: In file './docker-compose.yml' service 'version' doesn't have any configuration options. All top level keys in your docker-compose.yml must map to a dictionary of configuration options.
docker-compose run web npm test returned exit code 1
I tried the following solutions that show up on a very recent CircleCI forum post, but I didn't manage to get rid of the problem.
Upgrading both docker and docker-compose to the latest version is required:
machine:
pre:
- curl -sSL https://s3.amazonaws.com/circle-downloads/install-circleci-docker.sh | bash -s -- 1.10.0
- pip install --upgrade pip
- pip install docker-compose
services:
- docker
Why both?
Some say that upgrading docker-compose to the latest version by using pip is enough, but apparently is not (because the current Docker Engine CircleCI version does not support it, at least not anymore):
ERROR: The Docker Engine version is less than the minimum required by
Compose. Your current project requires a Docker Engine of version
1.10.0 or greater.
If you just upgrade Docker engine, it does not make any difference, since a higher docker-compose version is required to parse v2 YAML documents.