Using redis with Gitlab CI - redis

I am currently using serverless framework and setting up gitlab ci using shared runner.
Following is my gitlab-ci.yml:
image: node:latest
services:
- redis
cache:
paths:
- node_modules/
- java/
stages:
- build
- test
- review
- staging
- production
build:
stage: build
script:
- npm install
artifacts:
paths:
- node_modules/
install:java:
stage: build
script:
- apt-get update
- apt-get install -y default-jre default-jdk openjdk-7-jre openjdk-7-jdk
- apt-get update
- sls dynamodb install
artifacts:
paths:
- java/
connect:
image: redis
script:
- redis-cli -h redis PING
unit test:
stage: test
script:
- sls dynamodb start
- babel-node ./aws/createDB.js
- npm run unit
dependencies:
- build
- install:java
unit test job requires redis and is not able to connect. Following error gets thrown, when unit test job starts:
Error while creating redis client: Error: Redis connection to
127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Can someone point out what's wrong with current config file, thanks!

The host address of the redis service is redis not 127.0.0.1 or localhost.
So make sure you set the host for the redis service to redis in all of your scripts and configuration files.

Just to make people's life easier, I list an example .gitlab-ci.yml to configure Redis in Gitlab CI.
services:
- redis:latest
stages:
- test
test:
script:
- echo "hello world!"
stage: test
variables:
REDIS_PORT: 6379
REDIS_HOST: redis
REDIS_URL: redis://redis:6379

Related

Execute GitLab job only if files have changed in a subdirectory, otherwise use cached artefact in following job

I have a simple pipeline, comparable to this one:
image: docker:20
variables:
GIT_STRATEGY: clone
stages:
- Building - Frontend
- Building - Backend
include:
- local: /.ci/extensions/ci-variables.yml
- local: /.ci/extensions/docker-login.yml
Build Management:
stage: Building - Frontend
image: node:14-buster
script:
# Install needed dependencies for building
- apt-get update
- apt-get -y upgrade
- apt-get install -y build-essential
- yarn global add #quasar/cli
- yarn global add #vue/cli
# Install required modules
- cd ${CI_PROJECT_DIR}/resources/js/management
- npm ci --cache .npm --prefer-offline
# Build project
- npm run build
# Create archive
- tar czf ${CI_PROJECT_DIR}/dist-resources-js-management.tar.gz *
cache:
policy: pull-push
key:
files:
- ./resources/js/management/package-lock.json
paths:
- ./resources/js/management/.npm/
artifacts:
paths:
- dist-resources-js-management.tar.gz
Build Docker:
stage: Building - Backend
needs: [Build Management, Build Administration]
dependencies:
- Build Management
- Build Administration
variables:
CI_REGISTRY_IMAGE_COMMIT_SHA: !reference [.ci-variables, variables, CI_REGISTRY_IMAGE_COMMIT_SHA]
CI_REGISTRY_IMAGE_REF_NAME: !reference [.ci-variables, variables, CI_REGISTRY_IMAGE_REF_NAME]
before_script:
- !reference [.docker-login, before_script]
script:
- mkdir -p {CI_PROJECT_DIR}/public/static/management
- tar xzf ${CI_PROJECT_DIR}/dist-resources-js-management.tar.gz --directory ${CI_PROJECT_DIR}/public/static/management
- docker build
--pull
--label "org.opencontainers.image.title=$CI_PROJECT_TITLE"
--label "org.opencontainers.image.url=$CI_PROJECT_URL"
--label "org.opencontainers.image.created=$CI_JOB_STARTED_AT"
--label "org.opencontainers.image.revision=$CI_COMMIT_SHA"
--label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME"
--tag "$CI_REGISTRY_IMAGE_COMMIT_SHA"
-f .build/Dockerfile
.
I now want the first job to be executed under the following conditions:
Something has changed in the directory ${CI_PROJECT_DIR}/resources/js/management
This job has not yet created an artifact.
The last job should therefore always be able to access an artifact. If nothing has changed in the directory, it does not have to be created anew each time. If it did not exist before, it must of course be created.
Is there a way to map this in the GitLab Ci?
If I currently specify the dependencies and then work with only:changes: for the first job, GitLab complains if the job is not executed. Likewise with needs:.

GitLab CI configuration is invalid: stages config should be an array of strings

I getting an error on stages on that pipeline.
GitLab CI configuration is invalid: stages config should be an array of strings.
stages:
-test
-run
image: python:latest
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
test-asamasi:
stage: test
script:
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- python sslkontrol.py test
calistirma:
stage: run
script:
- python sslkontrol.py
On small mistake on the stages, you need to add an extra space between the - and test
I have tested your pipeline file above and I was able to get it working by adding space between - character and stage name(e.g - test) as shown below:
stages:
- test
- run
image: python:latest
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/pip
- venv/
test-asamasi:
stage: test
script:
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
- python sslkontrol.py test
calistirma:
stage: run
script:
- python sslkontrol.py
Recommendations
Now its easier to visualize, lint/validate your gitlab pipeline(e.g ) from within Gitlab console using this instructions Validate GitLab CI/CD configuration

Docker Tag Error 25 on gitlab-ci.yml trying to start GitLab Pipeline

I'm going through the "Scalable FastAPI Application on AWS" course. My gitlab-ci.yml file is below.
stages:
- docker
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
cache:
key: ${CI_JOB_NAME}
paths:
- ${CI_PROJECT_DIR}/services/talk_booking/.venv/
build-python-ci-image:
image: docker:19.03.0
services:
- docker:19.03.0-dind
stage: docker
before_script:
- cd ci_cd/python/
script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker build -t registry.gitlab.com/chris_/talk-booking:cicd-python3.9-slim .
- docker push registry.gitlab.com/chris_/talk-booking:cicd-python3.9-slim
My Pipeline fails with this error:
See https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
$ docker build -t registry.gitlab.com/chris_/talk-booking:cicd-python3.9-slim .
invalid argument "registry.gitlab.com/chris_/talk-booking:cicd-python3.9-slim" for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
Cleaning up project directory and file based variables
ERROR: Job failed: exit code 125
It may or may not be relevant but the Container Registry for the GitLab project says there's a Docker connection error.
Thanks
I created a new GitLab account with a new username and things are working now. The underscore does appear to have been the issue.

Gitlab CI/CD running Unit tests

I need to run unit tests on gitlab pipeline.
Here's my .gitlab-ci.yml:
stages:
- build
image: napp/php-ci:7.4-fpm
services:
- name: mysql:5.7
alias: mysql
variables:
MYSQL_ROOT_PASSWORD: pass_root
MYSQL_DATABASE: db_test
MYSQL_USER: user
MYSQL_PASSWORD: test
DATABASE_URL: 'mysql://user:test#mysql:3306/db_test'
build:
stage: build
only:
- master
- staging
services:
- mysql:5.7
script:
- apt-get update
- apt-get install zip unzip
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php
- php -r "unlink('composer-setup.php');"
- php composer.phar install
- php bin/console app:deploy:symfony:local
- ./vendor/bin/phpunit
On gitlab I have error: Access denied for user 'user'#'%' to database 'db_test_test'
Why it does not make tests on db_test but on 'db_test_test'`?
Can you please help me so I could run it appropriate db - db_test
Check your env.test file or any other environment file that you are using for testing. There will be a line which adds a prefix _test to your database name.

CircleCI Error migrating config to version 2

I am trying to migrating circleci 1.0 to 2.0 ,
and I got this error.
in job ‘build’: steps is not a list
can someone help me what is the reason ?
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.2.3-jessie
environment:
AWS_REGION: eu-central-1
steps:
- checkout
- run: echo "Tests are skipped because of static site."
- run: mkdir -p /tmp/test-data
deploy:
production:
branch: master
commands:
- bundle exec middleman s3_sync
The identation of the array below steps seems to be off. Try this:
steps:
- checkout
- run: echo "Tests are skipped because of static site."
- run: mkdir -p /tmp/test-data