Despliegue automático - Correcciones "build.yml" #72
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Push/PR - Master | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
env: | |
IMAGE_NAME_FUSE: "despensa-rest-api:0.0.1" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: 'maven' | |
- name: Compile with Maven | |
run: mvn -B compile --file pom.xml | |
- name: Test | |
run: mvn -B test --file pom.xml | |
- name: Report results to DeepSource | |
if: ${{ github.event_name != 'pull_request' }} | |
run: | | |
# Install deepsource CLI | |
curl https://deepsource.io/cli | sh | |
# From the root directory, run the report coverage command | |
./bin/deepsource report --analyzer test-coverage --key java --value-file ./target/site/jacoco/jacoco.xml | |
env: | |
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }} | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: 'maven' | |
- name: Compile with Maven | |
run: mvn -B package --file pom.xml -DskipTests | |
- name: Install CloudCaptain CLI | |
run: | | |
curl https://files.cloudcaptain.sh/com/boxfuse/client/boxfuse-commandline/1.36.2.2021/boxfuse-commandline-1.36.2.2021-linux-x64.tar.gz -o boxfuse-commandline.tar.gz | |
mkdir boxfuse | |
tar -xzf boxfuse-commandline.tar.gz -C boxfuse --strip-components=1 | |
${PWD}/boxfuse/boxfuse -v | |
- name: Write to config file | |
run: | | |
FILE_NAME="${PWD}/boxfuse/conf/boxfuse.conf" | |
echo "healthcheck=false" > $FILE_NAME | |
echo "ports.http=80" >> $FILE_NAME | |
echo "env=prod" >> $FILE_NAME | |
echo "logs.auto=false" >> $FILE_NAME | |
echo "logs.boot=false" >> $FILE_NAME | |
echo "components.openjdk=21.0.3" >> $FILE_NAME | |
echo "user=${{ secrets.BOXFUSE_USER }}" >> $FILE_NAME | |
echo "secret=${{ secrets.BOXFUSE_SECRET }}" >> $FILE_NAME | |
echo "envvars.MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }}" >> $FILE_NAME | |
echo "envvars.DATASOURCE_MYSQL_URL=${{ secrets.DATASOURCE_MYSQL_URL }}" >> $FILE_NAME | |
echo "envvars.MYSQL_USER=${{ secrets.MYSQL_USER }}" >> $FILE_NAME | |
echo "envvars.APP_SECURITY_JWT_SECRET=${{ secrets.APP_SECURITY_JWT_SECRET }}" >> $FILE_NAME | |
echo "envvars.FLYWAY_DEFAULT_SCHEMA=${{ secrets.FLYWAY_DEFAULT_SCHEMA }}" >> $FILE_NAME | |
echo "Secrets stored safely." | |
- name: Define the Image Name | |
run: | | |
IMAGE_NAME_FUSE_DATE=$IMAGE_NAME_FUSE.$(date +'%d%m%Y') | |
SEARCH_IMAGE=$(${PWD}/boxfuse/boxfuse ls -vault=true | grep -o "| [^/]*/$IMAGE_NAME_FUSE_DATE.[^|]*" | sed 's/^| //' | tail -n 1) | |
if [ -n "$SEARCH_IMAGE" ]; then | |
echo "Ya existe una imagen que contiene el texto $IMAGE_NAME_FUSE_DATE. Incrementando versión." | |
VERSION=$(echo "$SEARCH_IMAGE" | sed 's/ *$//' | grep -oE '[0-9]+$') | |
IMAGE_NAME_FUSE_DATE=$IMAGE_NAME_FUSE_DATE.$((VERSION + 1)) | |
else | |
echo "La imagen no existe." | |
IMAGE_NAME_FUSE_DATE=$IMAGE_NAME_FUSE_DATE.1 | |
fi | |
echo "IMAGE_NAME_FUSE_DATE=$IMAGE_NAME_FUSE_DATE" >> $GITHUB_ENV | |
- name: Fuses a Payload together with the Components it requires into an Image | |
run: | | |
RESULT=$(${PWD}/boxfuse/boxfuse fuse ${PWD}/target/despensa-rest-api.war -image=$IMAGE_NAME_FUSE_DATE | awk '/ERROR/{print $1}' | sed 's/://') | |
if [ "$RESULT" == "ERROR" ]; then | |
echo "Error fusing Image." | |
exit 1 | |
fi | |
- name: Removes the last Image from the CloudCaptain Vault | |
run: | | |
TOTAL=$(${PWD}/boxfuse/boxfuse ls -vault=true | awk '/Total:/ {print $2}') | |
echo "Total: $TOTAL" | |
if [ "$TOTAL" -eq 3 ]; then | |
IMAGE=$(${PWD}/boxfuse/boxfuse ls -vault=true | grep -o "| [^/]*/$IMAGE_NAME_FUSE.[^|]*" | sed 's/^| //' | head -n 1) | |
RESULT=$(${PWD}/boxfuse/boxfuse rm $IMAGE -vault=true | awk '/ERROR/{print $1}' | sed 's/://') | |
if [ "$RESULT" == "ERROR" ]; then | |
echo "Error removing Image." | |
exit 1 | |
fi | |
echo "Removed Image." | |
else | |
echo "No need to remove an Image." | |
fi | |
- name: Pushes this Image to the CloudCaptain Vault | |
run: | | |
RESULT=$(${PWD}/boxfuse/boxfuse push $IMAGE_NAME_FUSE_DATE | awk '/ERROR/{print $1}' | sed 's/://') | |
if [ "$RESULT" == "ERROR" ]; then | |
echo "Error pushing Image." | |
exit 1 | |
fi | |
- name: Run the Image Instance in the AWS environment | |
run: | | |
RESULT=$(${PWD}/boxfuse/boxfuse run $IMAGE_NAME_FUSE_DATE | awk '/ERROR/{print $1}' | sed 's/://') | |
if [ "$RESULT" == "ERROR" ]; then | |
echo "Error running Image." | |
exit 1 | |
fi | |
- name: Clean up secrets file | |
run: rm -f ${PWD}/boxfuse/conf/boxfuse.conf |