-
Notifications
You must be signed in to change notification settings - Fork 27
156 lines (124 loc) · 5.45 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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