AWS CodePipeline deploy Spring Boot application to Elastic BeansTalk no .jar file at root level of your source - spring-boot

I built a simple CodePipeline for a SpringBoot Java application with 3 steps:
Source: get the source from GitHub
Build: a jar file
Deploy: to an AWS Elastic Beanstalk instance
I had this error in logs
An error occurred during execution of command [app-deploy] -
[CheckProcfileForJavaApplication]. Stop running the command. Error:
there is no Procfile and no .jar file at root level of your source
bundle
My Buildspec:
version: 0.2
#env:
#variables:
# key: "value"
# key: "value"
#parameter-store:
# key: "value"
# key: "value"
#secrets-manager:
# key: secret-id:json-key:version-stage:version-id
# key: secret-id:json-key:version-stage:version-id
#exported-variables:
# - variable
# - variable
#git-credential-helper: yes
#batch:
#fast-fail: true
#build-list:
#build-matrix:
#build-graph:
phases:
install:
runtime-versions:
java: corretto11
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
#runtime-versions:
# name: version
# name: version
#commands:
# - command
# - command
#pre_build:
#commands:
# - command
# - command
build:
commands:
- mvn install
# - command
# - command
#post_build:
#commands:
# - command
# - command
#reports:
#report-name-or-arn:
#files:
# - location
# - location
#base-directory: location
#discard-paths: yes
#file-format: JunitXml | CucumberJson
artifacts:
files:
- target/sbk-0.0.2.jar
# - location
# - location
#name: $(date +%Y-%m-%d)
#discard-paths: yes
#base-directory: location
#cache:
#paths:
# - paths
it'is work fine when I upload manualy to EBS but when do it withe the pipeline , its doesnt work.
thanks in advance

I found the solution
AWS BS dont found the jar in the pckaging folder, he found target/xx.jar
What i did is i move the jar to main folder
with this commande
- mv target/*.jar app.jar
full of buildspec
version: 0.2
phases:
install:
runtime-versions:emphasized text
java: corretto11
commands:
- echo install
pre_build:
commands:
- echo pre_build
build:
commands:
- mvn package
- echo build
post_build:
commands:
- echo post_build
- mv target/*.jar app.jar
artifacts:
files:
- app.jar

Related

GitLab Shared runner, deploy spring boot microservice app to custom server

Before i start, let me tell you that i'm newbie to Gitlab CI file :)
i'm looking to automate deployments of spring boot microservice app to custom server (a namecheap VPS).
(I'm using the Gitlab shared runner)
i have used jHipster ci-cd to generate the .gitlab-ci.yml file. Doing that, i have: build, package, release stages working.
i even could see the image repository built in Gitlab Container registery.
What last, is the deployment. i know that i have to use a docker container to deploy it, but i don't know how.
I'm stuck in deploying the image repository to my VPS.
(as it's my first microservice, my VPS is still new, having only java installed).
Here is my .gitlab-ci.yml file:
#image: jhipster/jhipster:v6.9.0
image: openjdk:11-jdk
cache:
key: "$CI_COMMIT_REF_NAME"
paths:
- .maven/
stages:
- check
- build
# - test
# - analyze
- package
- release
- deploy
before_script:
- chmod +x mvnw
- git update-index --chmod=+x mvnw
- export NG_CLI_ANALYTICS="false"
- export MAVEN_USER_HOME=`pwd`/.maven
nohttp:
stage: check
script:
- ./mvnw -ntp checkstyle:check -Dmaven.repo.local=$MAVEN_USER_HOME
maven-compile:
stage: build
script:
- ./mvnw -ntp compile -P-webpack -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
paths:
- target/classes/
- target/generated-sources/
expire_in: 1 day
#maven-test:
# stage: test
# script:
# - ./mvnw -ntp verify -P-webpack -Dmaven.repo.local=$MAVEN_USER_HOME
# artifacts:
# reports:
# junit: target/test-results/**/TEST-*.xml
# paths:
# - target/test-results
# - target/jacoco
# expire_in: 1 day
maven-package:
stage: package
script:
- ./mvnw -ntp verify -Pprod -DskipTests -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
paths:
- target/*.jar
- target/classes
expire_in: 1 day
# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
docker-push:
stage: release
variables:
REGISTRY_URL: registry.gitlab.com
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
dependencies:
- maven-package
script:
- ./mvnw -ntp compile jib:build -Pprod -Djib.to.image=$IMAGE_TAG -Djib.to.auth.username=gitlab-ci-token -Djib.to.auth.password=$CI_BUILD_TOKEN -Dmaven.repo.local=$MAVEN_USER_HOME
docker-deploy:
image: docker:stable-git
stage: deploy
script:
when: manual
only:
- master
Thanks for your help :)

Why Sonar-scanner 4.2 is unable to create user cache?

Using a dockerized sonar scanner 4.2 official image I try to run a sample Docker run operation of the sonar scanner and I get
unable to create user cache: /usr/src/.sonar/cache caused by: Java.nio.file.accessdeniedexception: /usr/src/.sonar
everytime. Is it an issue with the user on the image? It's hard to believe since this is an official sonar scannerDocker image
Did you mount anything to /usr/src with -v "/path/to/project:/usr/src"?
On Linux, I had to create manually folders and set correct chmod :
mkdir .sonar .sonar/cache .scannerwork
sudo chmod -R 777 .sonar
sudo chmod -R 777 .scannerwork
To automize the scans, I created a docker-compose-sonarqube.yml which contains :
- the sonarqube server
- the sonarqube database
- tha sonarqube scanner
version: '3.7'
services:
# Sonarqube server : continuous code quality + security
# User = admin, password = admin
# The first time, we need to adjust docker parameters for sonarqube. Execute commands in the section 'Docker Host Requirements' from https://hub.docker.com/_/sonarqube/ : sudo sysctl -w vm.max_map_count=262144; sudo sysctl -w fs.file-max=65536; ulimit -n 65536; ulimit -u 4096; docker-compose -f docker-compose-sonarqube.yml up
sonarqube:
image: sonarqube:8.3-community
depends_on:
- sonarqube-db
ports:
- "54380:9000"
expose:
- "9000"
networks:
- sonarnet
environment:
SONAR_JDBC_URL: jdbc:postgresql://sonarqube-db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
- sonarqube_temp:/opt/sonarqube/temp
# Sonarqube database
sonarqube-db:
image: postgres
networks:
- sonarnet
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
volumes:
- postgresql:/var/lib/postgresql
# This needs explicit mapping due to https://github.com/docker-library/postgres/blob/4e48e3228a30763913ece952c611e5e9b95c8759/Dockerfile.template#L52
- postgresql_data:/var/lib/postgresql/data
# Sonarqube client (scanner)
sonarqube-scanner-cli:
image: sonarsource/sonar-scanner-cli
depends_on:
- sonarqube
networks:
- sonarnet
volumes:
- ./:/usr/src
environment:
SONAR_HOST_URL: http://sonarqube:9000
networks:
sonarnet:
driver: bridge
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
sonarqube_temp:
postgresql:
postgresql_data:
Set your project sources in sonar-project.properties :
# must be unique in a given SonarQube instance
sonar.projectKey=myapp
# --- optional properties ---
# defaults to project key
sonar.projectName=My App
# defaults to 'not provided'
#sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Defaults to .
sonar.sources=./symfony/src
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
# Sonarqube server url
sonar.host.url=http://sonarqube:9000
Finally run sonarqube.sh
# Usage : sh sonarqube.sh firefox
sonarcube() {
sonarqubePort=54380
sudo date # Ask for the password at the begining
docker-compose -f docker-compose-sonarqube.yml up --d
isServerUp=1
while [ "$isServerUp" != "0" ]; do # Wait for sonarcube server to be up
echo "Waiting for sonarqube. This may take 1 min ..."
curl http://localhost:$sonarqubePort -s|grep "window.serverStatus"|grep "UP"
isServerUp=$?
sleep 1
done
sleep 3
mkdir .sonar .sonar/cache .scannerwork
sudo chmod -R 777 .sonar
sudo chmod -R 777 .scannerwork
docker-compose -f docker-compose-sonarqube.yml start sonarqube-scanner-cli;
docker-compose -f docker-compose-sonarqube.yml logs -f sonarqube-scanner-cli;
firefox http://localhost:54380/dashboard?id=myapp
echo "View Sonarqube results at http://localhost:$sonarqubePort/dashboard?id=myapp"
}
sonarcube
I had the same problem under OpenShift with a Jenkins container configured with the Sonar scanner plugin.
To fix it I added an environment variable SONAR_USER_HOME, pointing to /tmp, at Jenkins's configuration, under Global Properties section.

How to configure aliases in YAML?

I'm trying to write some aliases into my YAML file but I keep getting an error. How can I configure aliases in YAML?
...rest_of_code
# DEFAULTS
checkout-and-attach: &checkout-and-attach
checkout:
path: ~/app
attach_workspace:
at: ~/app
# iOS Build and Test
build-and-test:
macos:
xcode: "10.2.0"
working_directory: ~/app/ios
steps:
<<: *checkout-and-attach # [ERROR]: Incorrect type expect array
...rest_of_code
I didn't find a way to spread an array with circleci.
In addition, I think that the references section must be before the jobs section.
Example for working config.yml with reference:
version: 2
references:
init_aws: &init_aws
run:
name: Init aws credentials
command: echo 1
init_env_vars: &init_env_vars
run:
name: Init environment variables
command: echo 2
jobs:
build:
docker:
- image: circleci/node:8.11.3
steps:
- *init_aws
- *init_env_vars

CodeBuild and CodeDeploy Success But Not Running Server for maven javaweb application

I'm using codestart on aws server my codecommit and codebuild success but not deployed on tomcat server. These are buildspec.yml and appspec.yml
buildspec.yml
version: 0.1
phases:
install:
commands:
- echo Entering install phase...
- wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
- tar xzvf apache-maven-3.3.9-bin.tar.gz -C /opt/
- export PATH=/opt/apache-maven-3.3.9/bin:$PATH
pre_build:
commands:
- echo Entering pre_build phase...
- echo Nothing to do in the pre_build phase...
build:
commands:
- echo Entering build phase...
- echo Build started on `date`
- mvn -f pom.xml compile war:exploded
post_build:
commands:
- echo Entering post_build phase...
- echo Build completed on `date`
- mv target/ROOT .
artifacts:
type: zip
files:
- target/ROOT.war
- appspec.yml
discard-paths: yes
appspec.yml
version: 0.0
os: linux
files:
- source: ./ROOT.jar
destination: /
Unless you provide any additional information on the errors, I'm not sure how to help you.
Couple of pointers:
You can go the Code Deploy > Deployments > Deployment Revision >
Events and logs to figure out exactly what is going wrong.
If you have ssh access to your instance, you can go to
/opt/code-deploy/deployment-root/deployment-logs to find out what is
going wrong.
buildspec.yml (need to modify)
appspec.yml (delete)
buildspec.yml
version: 0.1
phases:
install:
commands:
- echo Entering install phase...
- wget http://mirror.olnevhost.net/pub/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
- tar xzvf apache-maven-3.3.9-bin.tar.gz -C /opt/
- export PATH=/opt/apache-maven-3.3.9/bin:$PATH
pre_build:
commands:
- echo Entering pre_build phase...
- echo Nothing to do in the pre_build phase...
build:
commands:
- echo Entering build phase...
- echo Build started on `date`
- mvn -f pom.xml compile war:exploded
post_build:
commands:
- echo Entering post_build phase...
- echo Build completed on `date`
- mv target/ROOT .
artifacts:
type: zip
files:
- 'ROOT/WEB-INF/**/*'
- 'ROOT/WEB-INF/classes/*'
- 'ROOT/WEB-INF/classes/**/*'
- 'ROOT/WEB-INF/lib/*'
- 'ROOT/WEB-INF/lib-provided/*'
- 'ROOT/WEB-INF/js/*'
- 'ROOT/org/springframework/boot/loader/*' //if you are using spring boot application

GitLab Runner cache for Gradle is not working

I'm using GitLab Runner as CI to build an Android project however the cache is not working.
Here's my .gitlab-ci.yml. It was modified from https://gist.github.com/daicham/5ac8461b8b49385244aa0977638c3420.
image: runmymind/docker-android-sdk:latest
variables:
GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
stages:
- build
debug:
stage: build
script:
- set +e
- du -sh $CI_PROJECT_DIR/.gradle/wrapper
- du -sh $CI_PROJECT_DIR/.gradle/caches
- set -e
- ./gradlew assembleDebug
- mkdir artifacts
- cp mobile/build/outputs/apk/*.apk artifacts/
- cp wear/build/outputs/apk/*.apk artifacts/
cache:
paths:
- .gradle/wrapper/
- .gradle/caches/
- build/
- mobile/build/
- wear/build/
artifacts:
name: "project_${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
expire_in: 2 weeks
paths:
- artifacts/
And the log:
Running with gitlab-ci-multi-runner 9.0.0 (08a9e6f)
Using Docker executor with image runmymind/docker-android-sdk:latest ...
Using docker image sha256:d696fa13188c8d2d121c86cf526201b363c1e34ee7b163d6ce1ab1718f91a5e6 ID=sha256:d696fa13188c8d2d121c86cf526201b363c1e34ee7b163d6ce1ab1718f91a5e6 for predefined container...
Pulling docker image runmymind/docker-android-sdk:latest ...
Using docker image runmymind/docker-android-sdk:latest ID=sha256:474ac98077a496f2f71aa22ce4eebcea966c2960a061d4a59babe81ff007009b for build container...
Running on runner-8ce5d03c-project-72-concurrent-0 via outrage...
Cloning repository...
Cloning into '/builds/User/android-project'...
Checking out 015d01d0 as master...
Skipping Git submodules setup
Checking cache for default...
Successfully extracted cache
$ set +e
$ du -sh $CI_PROJECT_DIR/.gradle/wrapper
du: cannot access '/builds/User/android-project/.gradle/wrapper': No such file or directory
$ du -sh $CI_PROJECT_DIR/.gradle/caches
du: cannot access '/builds/User/android-project/.gradle/caches': No such file or directory
$ set -e
$ ./gradlew assembleDebug
Downloading https://services.gradle.org/distributions/gradle-3.4.1-all.zip
Unzipping /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do/gradle-3.4.1-all.zip to /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do
Set executable permissions for: /builds/User/android-project/.gradle/wrapper/dists/gradle-3.4.1-all/c3ib5obfnqr0no9szq6qc17do/gradle-3.4.1/bin/gradle
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.0/gradle-2.3.0.pom
(more downloads)
I have also tried using gradle argument to set gradle user home, aggressively specifying .gradle/ for cache, etc, but none of them worked.
Any ideas?
If you use Gitlab < 9.0,you add to specify the cache has to be shared among different pipelines.
Try to add key: $CI_PROJECT_NAME under cache:
image: runmymind/docker-android-sdk:latest
variables:
GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
stages:
- build
debug:
stage: build
script:
- set +e
- du -sh $CI_PROJECT_DIR/.gradle/wrapper
- du -sh $CI_PROJECT_DIR/.gradle/caches
- set -e
- ./gradlew assembleDebug
- mkdir artifacts
- cp mobile/build/outputs/apk/*.apk artifacts/
- cp wear/build/outputs/apk/*.apk artifacts/
cache:
key: $CI_PROJECT_NAME
paths:
- .gradle/wrapper/
- .gradle/caches/
- build/
- mobile/build/
- wear/build/
artifacts:
name: "project_${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}_${CI_COMMIT_SHA}"
expire_in: 2 weeks
paths:
- artifacts/

Resources