diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..97e5e2f --- /dev/null +++ b/appspec.yml @@ -0,0 +1,28 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ec2-user/server +permissions: + - object: / + pattern: "**" + owner: ec2-user + group: ec2-user +hooks: + BeforeInstall: + - location: scripts/server_clear.sh + timeout: 300 + runas: ec2-user + AfterInstall: + - location: scripts/fix_privileges.sh + timeout: 300 + runas: ec2-user + ApplicationStart: + - location: scripts/server_start.sh + timeout: 300 + runas: ec2-user + ApplicationStop: + - location: scripts/server_stop.sh + timeout: 300 + runas: ec2-user \ No newline at end of file diff --git a/build.gradle b/build.gradle index 83deb94..64fb0c5 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' runtimeOnly 'org.postgresql:postgresql' testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'com.h2database:h2' + runtimeOnly 'com.h2database:h2' } tasks.named('test') { diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 0000000..d6a932a --- /dev/null +++ b/buildspec.yml @@ -0,0 +1,35 @@ +version: 0.2 + +env: + variables: + PROFILE: "default" + DATASOURCE_URL: "pedra" + DATASOURCE_USERNAME: "papel" + DATASOURCE_PASSWORD: "tesoura" + LOGISTOCK_URL: "lagarto" + +phases: + install: + runtime-versions: + java: corretto17 + commands: + - chmod +w src/main/resources/application.yml + - sed -i "s|spring.profiles.active = .*|spring.profiles.active = ${PROFILE}|g" src/main/resources/application.yml + - sed -i "s|spring.datasource.url = .*|spring.datasource.url = ${DATASOURCE_URL}|g" src/main/resources/application.yml + - sed -i "s|spring.datasource.username = .*|spring.datasource.username = ${DATASOURCE_USERNAME}|g" src/main/resources/application.yml + - sed -i "s|spring.datasource.password = .*|spring.datasource.password = ${DATASOURCE_PASSWORD}|g" src/main/resources/application.yml + - sed -i "s|client.logistock.url = .*|client.logistock.url = ${LOGISTOCK_URL}|g" src/main/resources/application.yml + - cat src/main/resources/application.yml + + - chmod +x gradlew + build: + commands: + - ./gradlew bootJar + post_build: + commands: + - echo Build Completed +artifacts: + files: + - build/libs/*.jar + - scripts/*.sh + - appspec.yml \ No newline at end of file diff --git a/scripts/fix_privileges.sh b/scripts/fix_privileges.sh new file mode 100644 index 0000000..2a94baf --- /dev/null +++ b/scripts/fix_privileges.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +chmod +x /home/ec2-user/server/build/libs/*.jar +chmod +x /home/ec2-user/server/scripts/server_start.sh +chmod +x /home/ec2-user/server/scripts/server_stop.sh diff --git a/scripts/server_clear.sh b/scripts/server_clear.sh new file mode 100644 index 0000000..eee0673 --- /dev/null +++ b/scripts/server_clear.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +find /home/ec2-user/server -mindepth 1 -delete \ No newline at end of file diff --git a/scripts/server_start.sh b/scripts/server_start.sh new file mode 100644 index 0000000..887d586 --- /dev/null +++ b/scripts/server_start.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +cd /home/ec2-user/server/build/libs +sudo java -jar -Dserver.port=80 *.jar > /dev/null 2> /dev/null < /dev/null & \ No newline at end of file diff --git a/scripts/server_stop.sh b/scripts/server_stop.sh new file mode 100644 index 0000000..b477969 --- /dev/null +++ b/scripts/server_stop.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +sudo pkill -f 'java -jar' \ No newline at end of file diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index dea06fc..7deb096 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -2,6 +2,7 @@ spring: application: name: InvoiceAPI datasource: + driver-class-name: org.h2.Driver url: jdbc:h2:mem:testdb output: ansi: diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 673cd69..be1cc70 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,21 +7,12 @@ spring: url: jdbc:postgresql://localhost:5432/products username: postgres_user_product password: super_password - flyway: - enabled: true - url: jdbc:postgresql://localhost:5432/products - user: postgres_user_product - password: super_password - baselineOnMigrate: true output: ansi: enabled: ALWAYS jpa: open-in-view: true -server: - port: 8081 - client: logistock: url: http://localhost:8080 \ No newline at end of file