Skip to content

Commit

Permalink
Merge branch 'development' into feature/project-automatically-visible
Browse files Browse the repository at this point in the history
  • Loading branch information
arnedierick committed May 18, 2024
2 parents 355ff0b + ad77b1f commit 0d56e76
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
backend/app/src/main/resources/application-secrets.properties,spring.datasource.username=<username>
backend/app/src/main/resources/application-secrets.properties,spring.datasource.password=<password>
backend/app/src/main/resources/application-secrets.properties,azure.activedirectory.client-id=<client-id>
backend/app/src/main/resources/application-secrets.properties,azure.activedirectory.b2c.client-secret=<client-secret>
backend/app/src/main/resources/application-secrets.properties,azure.activedirectory.tenant-id=<tenant-id>
docker.env,PGU=<username>
docker.env,PGP=<password>
docker.env,POSTGRES_USER=${PGU}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ docker.env
./startBackend.sh
startBackend.sh

/.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -312,13 +314,24 @@ public static void removeDockerImage(String imageName) {
}

public static boolean imageExists(String image) {
DockerClient dockerClient = DockerClientInstance.getInstance();
try {
dockerClient.inspectImageCmd(image).exec();
} catch (Exception e) {
// Split the image into repository and tag
String[] parts = image.split(":");
String repository = parts[0];
String tag = parts.length > 1 ? parts[1] : "latest";

// Construct the URL for the Docker Hub API
String apiUrl = "https://hub.docker.com/v2/repositories/library/" + repository + "/tags/" + tag;
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int responseCode = connection.getResponseCode();

return (responseCode == 200);
} catch (IOException e) {
return false;
}
return true;
}

public static boolean isValidTemplate(String template) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ void zipFileInputTest() throws IOException {
}
@Test
void dockerImageDoesNotExist(){
assertFalse(DockerSubmissionTestModel.imageExists("BADUBADUBADUBADUBADUBADUB"));
assertFalse(DockerSubmissionTestModel.imageExists("BADUBADUBADUBADUBADUBADUB - miauw :3"));
assertFalse(DockerSubmissionTestModel.imageExists("alpine:v69696969"));
assertTrue(DockerSubmissionTestModel.imageExists("alpine:latest"));
}

Expand Down
28 changes: 28 additions & 0 deletions envBuilder.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@echo off
setlocal EnableDelayedExpansion

set "prevFile="

for /F "tokens=1,2 delims=," %%a in (.env) do (
echo Processing line: %%a,%%b
for /F "tokens=1,2 delims==" %%c in ("%%b") do (
echo File: %%a
echo Variable: %%c
echo Value: %%d

if not "%%a"=="!prevFile!" (
if exist %%a (
del %%a
echo Deleted file: %%a
)
type nul > %%a
echo Created file: %%a
)

echo. >> %%a
echo %%c=%%d >> %%a
echo Added variable to file

set "prevFile=%%a"
)
)
18 changes: 18 additions & 0 deletions envBuilder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ENV_FILE=".env"

while IFS= read -r line
do
echo "Processing line: $line"
IFS=',' read -r full_addr var <<< "$line"
IFS='=' read -r file env <<< "$full_addr"
echo "File: $file"
echo "Variable: $var"
echo "Value: $env"
touch "$file"
if ! grep -q "${var}=" "$file"; then
echo "Variable not set, appending to file..."
echo "${var}=${env}" >> "$file"
else
echo "Variable already set in file."
fi
done < "$ENV_FILE"

0 comments on commit 0d56e76

Please sign in to comment.