Gitlab runner with cassandra gitlab-ci.yml configururation - maven

I am trying to use a gitlab runner to run a maven project integration tests that need a cassandra database. I am not sure how to write the gitlab-ci.yml file. At the moment this is what I have
stages:
- test
test_job:
stage: test
script: "mvn clean verify -DlocalIntegrationTests=true"
when: on_success
except:
- production
Cassandra doesn't start up. How do I change the file to include cassandra starting up?

You can run cassandra as a service and connect to it from your test stage
services:
- cassandra
Here you will find how to access the service.

Related

Spring boot (Non Docker Application) with Github Actions - Unable to run jar file

I'm trying to deploy & run a java spring boot application using github actions to a AWS Ec2 Instance. The application properties file of spring boot application points to environment variables where are present in the AWS Ec2 Instance. However, these environment variables are not available when the github action runs and so the execution of the jar fails with a null pointer exception.
What is the correct way to deploy a Spring boot (Non Docker Application) to Self hosted Ec2 Server? Can I do it without needing AWS Code Pipeline or AWS Elastic Beanstalk?
How do we read Ec2 instance environment variables while using github actions.
Thanks.
Sample Workflow file:
jobs:
build:
runs-on: [self-hosted]
steps:
- uses: actions/checkout#v3
- name: Set up JDK 11
uses: actions/setup-java#v3
with:
java-version: "11"
distribution: "temurin"
cache: maven
- name: Build with Maven
run: mvn clean -B package
deploy:
runs-on: [self-hosted]
needs: build
steps:
- name: Run Script file
working-directory: ./
run: |
chmod +x ./script.sh
./script.sh
shell: bash
// script.sh - Try to print the env variables inside ec2.
#!/bin/bash
whoami
printenv

How to keep the local server running and run test on Travis CI

Trying to run some automated tests in TravisCI pipeline.
To run these tests, I need to keep my local server running on Travis.
And then run the automated test on that local server.
My automated tests are present in directory - sanity-tests.
Note- - cd $TRAVIS_BUILD_DIR/sanity-tests - yarn test these commands should only get triggered once the server is started and keep running. After tests are done we can close the server.
.yaml file
language: node_js
node_js: lts/*
services: xvfb
cache:
yarn: true
sudo: true
install: yarn
script:
- yarn install
- yarn start
- cd $TRAVIS_BUILD_DIR/sanity-tests
- yarn test
In the above script -
in the first 2 steps,- yarn install - yarn start - I'm installing dependencies and running my local server.
but because "yarn start" commands runs the local server and does not get exited, I'm not able to run the next commands which are - cd $TRAVIS_BUILD_DIR/sanity-tests - yarn test

How to deploy maven project on aws with Gitlab CI/CD

I'm trying to deploy a java maven project on aws with Gitlab CI/CD.
This is my .gitlab-ci.yml
image: maven:3-jdk-8
services:
- docker:dind
stages:
- test
- build
- deploy
maven-test:
stage: test
script:
- echo "Test stage"
- mvn clean validate compile test -B
maven-build:
stage: build
script:
- echo "Build stage"
- mvn install -B -DskipTests
artifacts:
paths:
- ./target/*.jar
maven-deploy:
stage: deploy
script:
- echo "Deploy stage"
- scp -v -o StrictHostKeyChecking=no -I "mykey.pem" ./target/*.jar ubuntu#xxxxxxx.com:*.jar
when: manual
If I execute the scp command on a terminal in my pc then the jar is uploaded in aws ec2 instance while in gitlab I have errors and the jar is not uploaded.
This is my first approach with Gitlab CI and aws, so can someone explain step by step what I need to do to deploy the project in aws ec2 instance with Gitlab CI?
Thanks!
Since you have not posted much about your problem nor did you post the error I will just suggest a few things to look at:
From a GitLab perspective:
Are you sure that the "mykey.pem" is available within the repository when running that command(maven-deploy) on the the gitlab-runner.?
Also are you sure that you are using a docker gitlab-runner, if you are not then you can't use the image: directive and therefore it might not not have mvn/scp locally.
You might want to look into the dependencies directive and ensure you make that artifact available in next task. This should be done by default!
From an AWS perspective:
Make sure that the ubuntu target machine/server has port 22 exposed to the EC2 machine running the gitlab-runner.
Edit:
If the error you are receiving is with the pem files permissions then take a look at this resolution for AWS EC2 pem file issue. Another similar resolution is here.
Seems like if you put chmod 400 mykey.pem before the scp it might fix your problem.

Travis-Ci after_deploy script is not working, and displaying success

This my .travis.yml file. I am trying to automate deployment to aws-codedeploy.
language: node_js
node_js:
- 7.10.0
services:
- mongodb
env:
- PORT=6655 IP="localhost" NODE_ENV="test"
script:
- npm start &
- sleep 25
- npm test
deploy:
provider: codedeploy
access_key_id:
secure: $Access_Key_Id
secret_access_key:
secure: $Access_Key_Secret
revision_type: github
application: Blog
deployment_group: Ayush-Bahuguna
region: us-east-2
after_deploy:
- "./build.sh"
Here build.sh is a shell script that generates the build files
cd /var/www/cms
sudo yarn install
npm run build-prod
And here is .gitignore file
node_modules/
client/dashboard/dist/
client/blog/dist/
The issue is that, even though travis-ci build succeeds, and after_deploy runs successfully, no build files are generated on the aws ec2 instance where my project is hosted.
Are you able to see any deployment created on your AWS CodeDeploy console? And are your able to see the deployment status? If there is a deployment created, but failed, you can try to see the reason why it failed. Even though the deployment succeeded, it doesn't equal to all instances are deployed depends on the deployment configuration: http://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-configurations.html.
Thanks,
Binbin

How to deploy laravel app on digitalocean after succesfull test pass on Gitalab CI

I have managed to succesfully run laravel test build on Gitlab CI using Gitlab Runner on digitaocean (With help from tutorial HOW TO: LARAVEL TESTING ON GITLAB CI WITH DOCKER)
Now I am wondering how I can deploy it after succesfull test.
This is my deploy process on my staging env:
cd MY_PROJECT_ROOT_DIR
git reset --hard HEAD
git checkout master
git pull
composer install
composer update
php artisan migrate
php artisan db:seed
How I can manage to include this deploy after test is done?
My configuration of GitLab Runner is the same as those files on this repo
This is the content of my .gitlab-ci.yml file:
before_script:
- bash .gitlab-ci.sh
variables:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: secret
phpunit:php-laravel-env:mysql:
image: woohuiren/php-laravel-env:latest
services:
- mysql:latest
script:
- php vendor/bin/phpunit --colors
How I should change this file in order to execute deploy script after test passed?
You need to use "stages"
Basically you would update your current test setup to include a stage.
stages:
- test
- deploy
phpunit:php-laravel-env:mysql:
stage: test
image: woohuiren/php-laravel-env:latest
services: ...
deploy_my_site:
stage: deploy
...
These stages will get run in sequence by GitLab but will stop if there is any error.
If you are using Forge you could use the deploy stage to trigger a script to curl the forge deploy hook.

Resources