2

I want to use this Docker image:

https://cloud.docker.com/u/steevanb/repository/docker/steevanb/php-code-sniffs

From this Dockerfile:

https://github.com/steevanb/docker-php-code-sniffs/blob/master/Dockerfile

Locally, i use it like that:

#!/bin/bash set -e readonly PROJECT_DIR=$(realpath $(dirname $(realpath $0))/..) docker run \ --rm \ -e PHPCS_PARAMETERS="--warning-severity=0 --ignore=/var/phpcs/var,/var/phpcs/vendor/" \ -e PHPCS_BOOTSTRAP=/var/phpcs.bootstrap.php \ -v ${PROJECT_DIR}:/var/phpcs:ro \ -v ${PROJECT_DIR}/phpcs.bootstrap.php:/var/phpcs.bootstrap.php:ro \ steevanb/php-code-sniffs:2.0.9 

I don't understand how i can use it in Gitlab CI, with same parameters?

I've tried some things, like that:

phpcs: image: name: steevanb/php-code-sniffs:2.0.9 entrypoint: ["/var/steevanb/php-code-sniffs/vendor/bin/phpcs", "$CI_PROJECT_DIR/project/user/src"] # don't need it, everything is done by overloading entrypoint script: echo $CI_PROJECT_DIR 

But i have this error, seems $CI_PROJECT_DIR is not replaced with the expected value:

RROR: The file "$CI_PROJECT_DIR/project/user/src" does not exist. 
3
  • 1
    What do you try to achieve? Please provide more information to us. Commented Sep 4, 2019 at 10:01
  • i want to call same docker run ... with Gitlab CI. I have a lot of errors when i try to do it, i can't write here all things i've tried it will be too long ;) Commented Sep 4, 2019 at 12:11
  • gitlab.com/gableroux/gitlab-ci-example-docker/blob/master/… check this example. things to understand form example, how to divide pipeline in stages , how to run docker commands and how to run on a particular branch.In case you want to run on particular runner looks for tags in gitlab doc. Hope this will help you to structure your pipline. Commented Sep 4, 2019 at 12:31

3 Answers 3

1

In order to use your own image in default runners, you need to put image In the beginning of .gitlab-ci.yml, you should write it like:

image: python:alpine before_script: - pip install mkdocs ... 
Sign up to request clarification or add additional context in comments.

3 Comments

it's not enough, see my example ;) i need to add some parameters to docker run, and i can't do it with image configuration.
Well, if I were you, I would write a new Dockerfile, use ADD and ENV to put the necessary files/environment variables into the image, push that into Dockerhub and use it like that if you want to use default runners.
i can't: i will not create a new image who contains my source code for each commit made. why can't i simply use a generic image, and add my parameters, with GitLab CI ? i had no problems with CircleCI before
0

If you are using gitlab CI/CD you can use your image by uploading the images to docker hub.

Steps to produce docker image:
1.compose a Docker file in your local machine.
2.build a docker image using that docker file.
3.name the docker image, create or login to docker hub
4.publish the image to you docker repository.

Reference: click here

1 Comment

0

You can pass environment variables using either GitLab Secret Variables (set in the project settings) or by specifying variables in .gitlab-ci.yml.

See GitLab CI YAML Variables documentation.

For example, in your .gitlab-ci.yml you may be able to specify:

variables: PHPCS_PARAMETERS: --warning-severity=0 --ignore=/var/phpcs/var,/var/phpcs/vendor/ PHPCS_BOOTSTRAP: PHPCS_BOOTSTRAP=/var/phpcs.bootstrap.php image: steevanb/php-code-sniffs:2.0.9 your_job: script: - your_script 

In this example, the variables and image are set globally. You can also set both of these within each job rather than globally.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.