Skip to content

Commit

Permalink
Merge pull request #111 from Softawii/chores/network
Browse files Browse the repository at this point in the history
chore: adding metric network to podman
  • Loading branch information
yaansz authored Oct 14, 2024
2 parents 69ec51a + 17db33f commit 4b0bb68
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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} \
Expand Down
15 changes: 2 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/softawii/capivara/config/SpringConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
management.metrics.distribution.percentiles-histogram.http.server.requests=true

security.basic.enabled=false
management.security.enabled=false
4 changes: 2 additions & 2 deletions start-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }


Expand Down

0 comments on commit 4b0bb68

Please sign in to comment.