Skip to content

Commit

Permalink
hotfix: remove outdated Docker cleanup scripts and replace with a uni…
Browse files Browse the repository at this point in the history
…fied cleanup system script
  • Loading branch information
LeonardoMeireles55 committed Feb 1, 2025
1 parent 426c87e commit bcd4407
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 53 deletions.
38 changes: 0 additions & 38 deletions .github/scripts/cleanup_docker.sh

This file was deleted.

49 changes: 49 additions & 0 deletions .github/scripts/cleanup_system.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Docker Cleanup Script

echo "====================================="
echo " Starting Docker Cleanup "
echo "====================================="

echo "Remove everything unused"
docker system prune -a -f

echo "====================================="
echo " Docker Cleanup Completed "
echo "====================================="

echo "Disk usage after cleanup:"
docker system df

echo "====================================="
echo " Starting System Cleanup "
echo "====================================="
echo "Clearing system cache..."
sync
echo 3 > /proc/sys/vm/drop_caches

echo "Memory usage after cleanup:"
free -h

echo "====================================="
echo " Starting APT Cleanup "
echo "====================================="

echo "Cleaning APT cache..."
apt-get clean -y

echo "Removing unused packages..."
apt-get autoremove -y

echo "Removing old downloaded archive files..."
apt-get autoclean -y

echo "Current disk usage:"
df -h

echo "====================================="
echo " Cleanup Complete "
echo "====================================="

exit 0
2 changes: 1 addition & 1 deletion .github/scripts/bk.json → .github/scripts/trivy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/backend-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Cleanup Docker resources
- name: Running cleanup script
run: |
chmod +x ./.github/scripts/cleanup_docker.sh
./.github/scripts/cleanup_docker.sh
chmod +x ./.github/scripts/cleanup_system.sh
./.github/scripts/cleanup_system.sh
notify:
runs-on: [ self-hosted, linux, x64, backend ]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# QualityLab Pro-API RESTful for internal laboratory quality control.

[![Docker Image CI/CD](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/docker-image.yml/badge.svg?branch=master)](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/docker-image.yml)
[![Docker Image CI/CD](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/backend-deploy.yml/badge.svg?branch=master)](https://github.com/LabGraphTeam/LabGraph-Back-End/actions/workflows/backend-deploy.yml)
<p align="center">

<img src="https://img.shields.io/static/v1?label=STATUS&message=In%20progress&color=RED&style=for-the-badge" alt="Em desenvolvimento"/>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@

import org.springframework.context.annotation.Configuration;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import leonardo.labutilities.qualitylabpro.utils.components.StringToLocalDateTimeConverter;


@Configuration
@EnableSpringDataWebSupport
public class WebConfig {
}
public class WebConfig implements WebMvcConfigurer {

private final StringToLocalDateTimeConverter dateTimeConverter;

public WebConfig(StringToLocalDateTimeConverter dateTimeConverter) {
this.dateTimeConverter = dateTimeConverter;
}

@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(dateTimeConverter);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
package leonardo.labutilities.qualitylabpro.utils.components;

import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.List;

@Component
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {

private static final DateTimeFormatter FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final List<DateTimeFormatter> DATE_FORMATTERS = Arrays.asList(
DateTimeFormatter.ISO_DATE_TIME, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"),
DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"),
DateTimeFormatter.ofPattern("yyyy-MM-dd"), DateTimeFormatter.ofPattern("dd/MM/yyyy"));

@Override
@NonNull
public LocalDateTime convert(@NonNull String source) {
return LocalDateTime.parse(source, FORMATTER);
}
@Override
public LocalDateTime convert(String source) {
if (source == null || source.trim().isEmpty()) {
return null;
}

// Sanitize input
source = sanitizeDate(source);

DateTimeParseException lastException = null;

for (DateTimeFormatter formatter : DATE_FORMATTERS) {
try {
if (source.length() <= 10) {
LocalDate date = LocalDate.parse(source, formatter);
return LocalDateTime.of(date, LocalTime.MIDNIGHT);
} else {
return LocalDateTime.parse(source, formatter);
}
} catch (DateTimeParseException e) {
lastException = e;
}
}

throw new IllegalArgumentException("Unable to parse date: " + source, lastException);
}

private String sanitizeDate(String date) {
return date.trim().replaceAll("--", "-") // Fix double dashes
.replaceAll("\\s+", " ") // Fix multiple spaces
.replaceAll("T\\s", "T") // Fix space after T
.replaceAll("\\s(\\d:\\d)", "T$1") // Add T between date and time if missing
.replaceAll("(\\d)(\\s00:00:00)", "$1T00:00:00"); // Standardize midnight time
// format
}
}

0 comments on commit bcd4407

Please sign in to comment.