Github action gradle build cannot create application properties file in jar file - java

I'm building CI/CD using Spring Boot, gradle, GitHub Actions, Docker, AWS.
application properties is separate (application-dev.properties, application-prod.properties) and generates files in GitHub-Actions like that
## make application-dev.properties
- name: make application-dev.properties
if: contains(github.ref, 'feature/#125-CICD')
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resource
cd ./src/main/resource
touch ./application-dev.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-dev.properties
cat application-dev.properties
shell: bash
env:
DEV_PROP: ${{ secrets.PROPERTIES_DEV }}
It's working fine and created file
next, after build with gradle, when i extracted the jar file after building the gradle and checked it, the properties file does not exist.
check jar file code like that
## check jar file
- name: check jar file
if: contains(github.ref, 'feature/#125-CICD')
run: |
pwd
ls -a .
cd ./build/libs
ls -a .
jar xvf Web-Team-2-Backend-0.0.1-SNAPSHOT.jar
ls -a .
cd ./BOOT-INF/classes
pwd
ls -a .
shell: bash
If you check the result, the application-dev.properties file created before does not exist...
What's the problem?
the full code is as follows:
name: CI/CD
# event trigger
on:
push:
branches:
- main
- develop
- feature/#125-CICD
permissions:
contents: read
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
## jdk setting
- uses: actions/checkout#v3
- name: Set up JDK 11
uses: actions/setup-java#v3
with:
java-version: '11'
distribution: 'temurin' # https://github.com/actions/setup-java
## gradle caching
- name: Gradle Caching
uses: actions/cache#v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
## make application-dev.properties
- name: make application-dev.properties
if: contains(github.ref, 'feature/#125-CICD')
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resource
cd ./src/main/resource
touch ./application-dev.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-dev.properties
cat application-dev.properties
shell: bash
env:
DEV_PROP: ${{ secrets.PROPERTIES_DEV }}
## gradle build
- name: Build with Gradle
run: ./gradlew build -x test -x ktlintCheck -x ktlintTestSourceSetCheck -x ktlintMainSourceSetCheck -x ktlintKotlinScriptCheck
## check jar file
- name: check jar file
if: contains(github.ref, 'feature/#125-CICD')
run: |
pwd
ls -a .
cd ./build/libs
ls -a .
jar xvf Web-Team-2-Backend-0.0.1-SNAPSHOT.jar
ls -a .
cd ./BOOT-INF/classes
pwd
ls -a .
shell: bash

i solved this problem..
path is resources, not resource :(
## make application-dev.properties
- name: make application-dev.properties
if: contains(github.ref, 'feature/#125-CICD')
run: |
echo "ls -a . & pwd"
pwd
ls -a .
echo "mkdir & touch"
mkdir -p ./src/main/resource << here !!
cd ./src/main/resource
touch ./application-dev.properties
pwd
ls -a .
echo "copy properties"
echo $DEV_PROP >> ./application-dev.properties
cat application-dev.properties
shell: bash
env:
DEV_PROP: ${{ secrets.PROPERTIES_DEV }}

Related

Error response from daemon: ADD failed: no source files were specified

Dockerfile:
FROM openjdk:11-jre-slim
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
JHIPSTER_SLEEP=0 \
JAVA_OPTS=""
# Add a jhipster user to run our application so that it doesn't need to run as root
RUN adduser --disabled-login --shell /bin/sh --gecos "" jhipster
WORKDIR /home/jhipster
ADD entrypoint.sh entrypoint.sh
RUN chmod 755 entrypoint.sh && chown jhipster:jhipster entrypoint.sh
USER jhipster
ADD *.jar contourservice.jar
ENTRYPOINT ["./entrypoint.sh"]
EXPOSE 8084
entrypoint.sh:
#!/bin/sh
echo "The application will start in ${JHIPSTER_SLEEP}s..." && sleep "${JHIPSTER_SLEEP}"
exec java "${JAVA_OPTS}" -Djava.security.egd=file:/dev/./urandom -jar "${HOME}/contourservice.jar" "$#"
console:
Step 8/10 : ADD *.jar contourservice.jar
Error response from daemon: ADD failed: no source files were specified
I try to exec command docker build src/main/docker/
but in step 8, when docker try to ADD *.jar it failed.
It is my hierarchy:

Docker Build can't find GradleWrapperMain on GitLab but works on my laptop

Docker build works on my laptop but on GitLab I get
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Tried a lot of different setups but nothing works...fails at gradlew build...Any ideas are welcome
My .gitlab-ci.yaml
....variables here
publish:
image:
name: amazon/aws-cli
entrypoint: [""]
services:
- docker:dind
before_script:
- amazon-linux-extras install docker
- aws --version
- docker --version
- export GRADLE_USER_HOME=`pwd`/gradle
- export CLASSPATH=`pwd`/gradle/wrapper
cache:
paths:
- gradle/wrapper
- .gradle/wrapper
- .gradle/caches
script:
- docker build -t $DOCKER_REGISTRY/$APP_NAME:$CI_PIPELINE_IID .
My Dockerfile
FROM openjdk:11
ENV wdir=code
ENV MY_SERVICE_PORT=8080
WORKDIR /$wdir
COPY . /code
RUN echo "Running build"
RUN ["/code/gradlew", "build"]
EXPOSE $MY_SERVICE_PORT
# Run the service
CMD ["java", "-jar", "build/libs/code-1.0-SNAPSHOT.jar"]
Created a workaround by installing gradle...works now:
FROM openjdk:11
ENV wdir=code
ENV MY_SERVICE_PORT=8080
WORKDIR /code
# Install Gradle
RUN wget -q https://services.gradle.org/distributions/gradle-6.5-bin.zip \
&& unzip gradle-6.5-bin.zip -d /opt \
&& rm gradle-6.5-bin.zip
ENV GRADLE_HOME /opt/gradle-6.5
ENV PATH $PATH:/opt/gradle-6.5/bin
# Prepare by downloading dependencies
ADD build.gradle /code/build.gradle
ADD src /code/src
RUN echo "Running build"
RUN cd /code
RUN gradle --no-daemon build
EXPOSE $MY_SERVICE_PORT
# Run the service
CMD ["java", "-jar", "build/libs/code-1.0-SNAPSHOT.jar"]

Logs stucks when deployment is done through teamcity

Recently we migrated to Teamcity deployment from manual process. Ours is java application on linux server.
Whenever deployment is done through Teamcity, logs are stuck i.e. after shutdown log messages nothing else is printed in the logs. Then we run manual stop and start scripts on the server to get the logs running.
Looks like somehow Teamcity locks log file and doesn't release it.
How to overcome it?
In Teamcity, deploy step is defined as below:
REMOTE_PATH="/opt/app/$ARTIFACT/releases/teamcity"
cd $TEAMCITY_REPO_HOME/$ARTIFACT/build/libs
echo "Uploading artifact"
ssh $UAT_HOST -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "mkdir -p $REMOTE_PATH"
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $ARTIFACT.jar $UAT_HOST:$REMOTE_PATH
echo "Stopping service"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "sh /opt/app/$ARTIFACT/stop.sh"
sleep 3s
echo "Copying new artifact"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "cp $REMOTE_PATH/$ARTIFACT.jar /opt/app/$ARTIFACT"
sleep 6s
echo "Starting service"
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $UAT_HOST "sh /opt/app/$ARTIFACT/start.sh"
Taking ideas from above comments of Andy Dufresne, I created one deploy script as below:
This single script stops server, takes backup of current artifact, copies new build and then executes start script to start the server.
#!/bin/bash
#check for correct number of arguments
if [ "$#" -ne 1 ]; then
echo "Incorrect number of arguments, exiting..."
exit 1
fi
ARTIFACT=$1
cd "/opt/app/$ARTIFACT"
echo $(pwd)
echo "Stopping service"
bash stop.sh
sleep 3s
echo "Tagging artifact with release"
cp "releases/teamcity/$ARTIFACT.jar" "releases/teamcity/$ARTIFACT`date +'_%y_%m_%d'`.jar"
echo "Deleting old releases"
cd "releases/teamcity" && \
ls | grep -v '/$' | head -n -6 | xargs -d '\n' -r rm -- && \
cd "/opt/app/$ARTIFACT" && \
ls -l "releases/teamcity"
echo "Copying new artifact"
cp "releases/teamcity/$ARTIFACT.jar" .
echo "Starting service"
bash start.sh
sleep 2s
This script is called from team-city in its build steps(previously stopping server, copying artifact and starting server all were done by teamcity explicitly as outlined in the question.)
Now teamcity build step looks concise as under and WORKS as expected(that important !!!):
REMOTE_PATH="/opt/app/$ARTIFACT/releases/teamcity"
cd $TEAMCITY_REPO_HOME/$ARTIFACT/build/libs
echo "Uploading artifact"
ssh -o "StrictHostKeyChecking=no" "$UAT_HOST" "mkdir -p $REMOTE_PATH"
scp -o "StrictHostKeyChecking=no" "$ARTIFACT.jar" "$UAT_HOST:$REMOTE_PATH"
echo "Deploying artifact"
ssh -o "StrictHostKeyChecking=no" "$UAT_HOST" "sh /opt/app/$ARTIFACT/deploy.sh $ARTIFACT"

Java commands in Eclim

When I run eclim -? commands, I get the following output.
Available Commands:
archive_read -f file
history_add -p project -f file
history_clear -p project -f file
history_list -p project -f file
history_revision -p project -f file -r revision
jobs [-f family]
locate_file -p pattern -s scope [-n project] [-f file]
[-i]
ping
problems -p project [-e]
project_build -p project
project_by_resource -f file
project_close -p project
project_create -f folder [-p name] -n natures [-d depends]
[-a args]
project_delete -p project
project_import -f folder
project_info -p project
project_link_resource -f file
project_list [-n nature]
project_move -p project -d dir
project_nature_add -p project -n nature [-a args]
project_nature_aliases [-m]
project_nature_remove -p project -n nature
project_natures [-p project]
project_open -p project
project_refresh -p project
project_refresh_file -p project -f file
project_rename -p project -n name
project_run [-p project] [-v vim_instance_name] [-x vim_executable] [-l]
[-d] [-c] [-n name]
project_run_terminate [-l launchid]
project_setting -p project -s setting [-v value]
project_settings [-p project]
project_update -p project [-b buildfile] [-s settings]
projects
refactor_redo [-p]
refactor_undo [-p]
reload
setting -s setting
settings
settings_update [-s settings]
shutdown
workspace_dir
xml_format -f file -w linewidth -i indent -m fileformat
xml_validate -p project -f file [-s]
I do not see Java commands such as java_search or java_element_doc. How can I access them?
I have installed eclim version 2.5, and selected "Java Development" in the installation menu.

bash script to extract jar file and copy the path

I am a PhD student of software testing. I made a script to test all the classes in a specific folder. However to make it fully automatic I would need a script that extract all the jar files in a respective folder and copy both the paths before and after extracting the jar file. For example
If I have AAA.jar at location /Users/mian/Systems/AAA.jar and AAA.jar on extraction create the folders and class org/apple/orange/banana.class then I would like to separately assign org/apple/orange/ to variable VAR1 and /Users/mian/Systems/org/apple/orange/ to VAR2.
The script I have so far is this
#!/bin/bash
STR1="/Users/mian/QualitasCorpus/Systems/freecs/freecs-1.3.20100406/bin/freecs-1.3.20100406/lib/"
STR2="freecs.commands."
for i in $( ls $STR1 ); do
if [[ $i == *.class ]]
then
echo " ################## The Class under test is "$i" ############################" >> result.traces
java yeti.YetiWithDaikon -java -time=10s -nologs -ADFDPlus -testModules="$STR2${i%.*}" >> result.traces
echo " %%%%%%%%%%%%%%%%%%%% The Class is finished testing %%%%%%%%%%%%%%%%%%%%%%%%%" >> result.traces
fi
done
echo "##################################################################################" >> result.traces
echo "############################### End of Folder ####################################" >> result.traces
echo "##################################################################################" >> result.traces
mv result.traces resultsOf"$STR2"traces
This script writes info about the jar file. Names of variables are included in echo.
#!/bin/bash
echo ""
STR1=$(dirname $(realpath $1".jar"))
unzip -qo $1".jar" -d $1 #unzip jar file to working_directory/jarname/
list=$(tree $1 -Rnfi --noreport | grep ".class") #gets the raw .class file list
list=$(echo $list | sed -e 's/'$1'\.//g') #removes the first foldername
list=$(echo $list | sed -e 's/\/class//g') #removes the last .class
list2=$list
list=$(echo $list | sed -e 's/\//\./g') #changes / to .
OLD_IFS=$IFS
IFS=$'\n'" "
echo -e "STR1=\033[34m"$STR1"\033[0m\n"
echo -e "FOLDER=\033[31m"$1"\033[0m\n"
for STR2 in $list
do
echo -e "STR2=\033[32m"$STR2"\033[0m"
done
echo ""
for STR3 in $list2
do
echo -e "STR3=\033[33m"$STR3"\033[0m"
done
echo ""
IFS=$OLD_IFS
Usage:
You have a jar file called freecs.jar. Run it with:
SCRIPTNAME jarfilename
without the .jar extension.

Categories