diff --git a/.github/workflows/deploy-prod.yaml b/.github/workflows/deploy-prod.yaml index 6d54336..6a04bd4 100644 --- a/.github/workflows/deploy-prod.yaml +++ b/.github/workflows/deploy-prod.yaml @@ -69,4 +69,4 @@ jobs: key: ${{ secrets.VM_SSH_PRIVATE_KEY }} script: | cd /home/${{ secrets.SSH_USERNAME }}/capivara - DISCORD_TOKEN='${{ secrets.DISCORD_BOT_TOKEN }}' LOG_CHANNEL_ID='${{ secrets.DISCORD_LOG_CHANNEL_ID }}' CURUPIRA_RESET='true' DATABASE_DRIVER='org.postgresql.Driver' DATABASE_DIALECT='org.hibernate.dialect.PostgreSQL95Dialect' DATABASE_URL='jdbc:postgresql://host.containers.internal:5432/capivara' DATABASE_USERNAME='${{ secrets.DATABASE_USERNAME }}' DATABASE_PASSWORD='${{ secrets.DATABASE_PASSWORD }}' JAVA_ARGS='-Xmx350M' /bin/bash start-container.sh docker.io/eduardoferro/capivara:${{ github.sha }} + DISCORD_TOKEN='${{ secrets.DISCORD_BOT_TOKEN }}' LOG_CHANNEL_ID='${{ secrets.DISCORD_LOG_CHANNEL_ID }}' CURUPIRA_RESET='true' DATABASE_DRIVER='org.postgresql.Driver' DATABASE_DIALECT='org.hibernate.dialect.PostgreSQL95Dialect' DATABASE_URL='jdbc:postgresql://capivara_database:5432/capivara' DATABASE_USERNAME='${{ secrets.DATABASE_USERNAME }}' DATABASE_PASSWORD='${{ secrets.DATABASE_PASSWORD }}' JAVA_ARGS='-Xmx350M' /bin/bash start-container.sh docker.io/eduardoferro/capivara:${{ github.sha }} diff --git a/Dockerfile b/Dockerfile index 82b4c72..b5a6cbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,6 @@ COPY --from=builder /app . ENV JAVA_ARGS="-Xmx350M" ENV LOG_DIRECTORY="/app/logs" -ENV SPRING_CONFIG_LOCATION="/app/main.properties" ENV DISCORD_TOKEN="invalid" ENV CURUPIRA_RESET="true" ENV LOG_CHANNEL_ID="invalid" @@ -30,7 +29,6 @@ ENV DATABASE_PASSWORD="database-password" ENTRYPOINT java ${JAVA_ARGS} -jar CapivaraBot.jar \ --token=${DISCORD_TOKEN} \ - --spring.config.location=file:${SPRING_CONFIG_LOCATION} \ --curupira.reset=${CURUPIRA_RESET} \ --log.directory=${LOG_DIRECTORY} \ --log.channel.id=${LOG_CHANNEL_ID} \ diff --git a/build.gradle b/build.gradle index 20ad79c..e166ebe 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,6 @@ dependencies { exclude module: 'spring-boot-starter-logging' } - implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.7.0' implementation 'javax.xml.bind:jaxb-api:2.3.1' implementation 'com.h2database:h2:2.1.212' @@ -59,20 +58,10 @@ tasks.register('deploy') { jar { enabled = false } - shadowJar { + bootJar { archiveFileName = "CapivaraBot.jar" } - dependsOn 'shadowJar' -} - -tasks.register('homolog') { - jar { - enabled = false - } - shadowJar { - archiveFileName = "CapivaraBotHomolog.jar" - } - dependsOn 'shadowJar' + dependsOn 'bootJar' } test { diff --git a/src/main/java/com/softawii/capivara/config/SpringConfig.java b/src/main/java/com/softawii/capivara/config/SpringConfig.java index af11e49..641cdd6 100644 --- a/src/main/java/com/softawii/capivara/config/SpringConfig.java +++ b/src/main/java/com/softawii/capivara/config/SpringConfig.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @@ -38,8 +39,6 @@ public class SpringConfig { private static final Logger LOGGER = LogManager.getLogger(SpringConfig.class); private final Environment env; - @Value("${token}") - private String discordToken; public SpringConfig(Environment env) { this.env = env; @@ -63,7 +62,9 @@ public LocalContainerEntityManagerFactoryBean entityManagerFactory() { } @Bean - public JDA jda() { + public JDA jda(ApplicationArguments args) { + String discordToken = args.getOptionValues("token").get(0); + JDA jda; try { JDABuilder builder = JDABuilder.create( diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7131a7a..81bd982 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -12,4 +12,7 @@ management.metrics.tags.application=${spring.application.name} management.endpoints.web.exposure.include=prometheus management.metrics.export.prometheus.enabled=true server.tomcat.mbeanregistry.enabled=true -management.metrics.distribution.percentiles-histogram.http.server.requests=true \ No newline at end of file +management.metrics.distribution.percentiles-histogram.http.server.requests=true + +security.basic.enabled=false +management.security.enabled=false \ No newline at end of file diff --git a/start-container.sh b/start-container.sh index 9debda8..78b0a97 100644 --- a/start-container.sh +++ b/start-container.sh @@ -11,7 +11,7 @@ if [[ -z "${DISCORD_TOKEN}" ]] || [[ -z "${LOG_CHANNEL_ID}" ]] ; then exit 1 fi -CONTAINER_NAME="capivara_bot" +CONTAINER_NAME="capivarabot" OLD_CONTAINER_ID=$(podman ps --all --quiet --filter "name=$CONTAINER_NAME") if [[ -z "${OLD_CONTAINER_ID}" ]]; then @@ -40,7 +40,7 @@ podman run -d \ --memory 400M \ --name $CONTAINER_NAME \ --restart always \ - --network slirp4netns:allow_host_loopback=true \ + --network metrics \ $CONTAINER_REPOSITORY || { echo 'Failed to start container failed'; exit 1; }