From 8cd0ff0a464ad3eec778f0ea3704d254cda49bd1 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:02:33 +0100 Subject: [PATCH 01/13] start work on auto downloading the public directory images --- Dockerfile | 2 +- start.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index 4758522..cc5ba3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,4 +24,4 @@ ENV NODE_ENV=production EXPOSE 3000 # Start the app -CMD ["npm", "start"] \ No newline at end of file +CMD ["bash", "start.sh"] \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..5f127e6 --- /dev/null +++ b/start.sh @@ -0,0 +1,5 @@ +if [ -z "$(ls -A /usr/src/app/public)" ]; then + echo "Directory is empty" +fi + +node start \ No newline at end of file From f6df0f44f265748b25d2de84ae812f61de0833d2 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:06:48 +0100 Subject: [PATCH 02/13] add logs --- start.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 5f127e6..8394c56 100644 --- a/start.sh +++ b/start.sh @@ -1,5 +1,7 @@ +echo "Checking if files need to be downloaded" if [ -z "$(ls -A /usr/src/app/public)" ]; then echo "Directory is empty" fi -node start \ No newline at end of file +echo "Starting Simple Links..." +npm start \ No newline at end of file From f6e4e98965351a41aa85affb1640e2774b0d979b Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:16:41 +0100 Subject: [PATCH 03/13] add basic download test --- start.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 8394c56..cf1f210 100644 --- a/start.sh +++ b/start.sh @@ -1,6 +1,25 @@ +workDir=/usr/src/app + +baseUrl=https://git.fascinated.cc/Fascinated/simple-links/raw/branch/master/public/ +toDownload=("avatar.webp" "background.jpg") + echo "Checking if files need to be downloaded" -if [ -z "$(ls -A /usr/src/app/public)" ]; then - echo "Directory is empty" +if [ -z "$(ls -A $workDir/public)" ]; then + echo "Some files are missing, downloading them" + if [ ! -w "$workDir" ]; then + echo "The directory \"$workDir\" is not writeable, unable to download files. Please check your docker compose for :ro and set it to :rw" + for item in "${toDownload[@]}" + do + dir=$workDir/public/$item + if [ -e "$dir" ]; then + echo "Downloading $item to directory $dir" + wget -P $dir $baseUrl$item + echo "Done" + fi + done + echo "Finished downloading files!" +else + echo "All files are already present, no need to download" fi echo "Starting Simple Links..." From c28f50f49ea82b8f309b131484555096e1a7b769 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:17:06 +0100 Subject: [PATCH 04/13] fix check --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index cf1f210..3071047 100644 --- a/start.sh +++ b/start.sh @@ -11,7 +11,7 @@ if [ -z "$(ls -A $workDir/public)" ]; then for item in "${toDownload[@]}" do dir=$workDir/public/$item - if [ -e "$dir" ]; then + if [ ! -e "$dir" ]; then echo "Downloading $item to directory $dir" wget -P $dir $baseUrl$item echo "Done" From 98b7ad12cc4fc1daad4b64d8c48865fec6913eb1 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:18:43 +0100 Subject: [PATCH 05/13] enable public directory by default --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 14f76ad..1d4dea8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,4 +14,4 @@ services: - 3000:3000 volumes: - ./config.json:/usr/src/app/config.json:ro # The application config (Must be created before starting the service) - #- ./public:/usr/src/app/public:ro # Used for public facing images (uncomment if you are using your own images - see the public directory) + - ./public:/usr/src/app/public:rw # Used for public facing images (uncomment if you are using your own images - see the public directory) From 0dd750a115d681e6f5aaaa7ac27d62673b85ea94 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:20:53 +0100 Subject: [PATCH 06/13] fix if statement --- start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/start.sh b/start.sh index 3071047..f8eff65 100644 --- a/start.sh +++ b/start.sh @@ -8,6 +8,7 @@ if [ -z "$(ls -A $workDir/public)" ]; then echo "Some files are missing, downloading them" if [ ! -w "$workDir" ]; then echo "The directory \"$workDir\" is not writeable, unable to download files. Please check your docker compose for :ro and set it to :rw" + fi for item in "${toDownload[@]}" do dir=$workDir/public/$item From 4d8ea7f95b99bad629f0239fb1b2efbb90dfd581 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:23:50 +0100 Subject: [PATCH 07/13] install wget --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index cc5ba3b..c401549 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,8 @@ FROM node:lts-slim ENV NODE_ENV=production WORKDIR /usr/src/app +RUN apt install wget + # Copy package.json and package-lock.json separately to fully utilize Docker layer caching COPY package.json ./ COPY package-lock.json ./ From e14f1559458088ed53f12c7bc74982457b1adece Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:24:42 +0100 Subject: [PATCH 08/13] fix missing wget package --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c401549..99dc4eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM node:lts-slim ENV NODE_ENV=production WORKDIR /usr/src/app +RUN apt update RUN apt install wget # Copy package.json and package-lock.json separately to fully utilize Docker layer caching From 19fde36765e1c782b216255e87dd08219ad5cc28 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:25:57 +0100 Subject: [PATCH 09/13] fix installing wget --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 99dc4eb..fab7bf9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV NODE_ENV=production WORKDIR /usr/src/app RUN apt update -RUN apt install wget +RUN DEBIAN_FRONTEND=noninteractive apt install wget # Copy package.json and package-lock.json separately to fully utilize Docker layer caching COPY package.json ./ From 6cf6227a10ce2c32a19230d399f8d0dcc14a1c27 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:26:54 +0100 Subject: [PATCH 10/13] fix the fixing of the fix kind --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fab7bf9..3b0b10e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ENV NODE_ENV=production WORKDIR /usr/src/app RUN apt update -RUN DEBIAN_FRONTEND=noninteractive apt install wget +RUN DEBIAN_FRONTEND=noninteractive apt install wget -y # Copy package.json and package-lock.json separately to fully utilize Docker layer caching COPY package.json ./ From 1379ee5de5aecd10d530e99cd03fe11e780ffd1a Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:35:49 +0100 Subject: [PATCH 11/13] make wget less verbose --- docker-compose.yml | 2 +- start.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1d4dea8..58841d6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,4 +14,4 @@ services: - 3000:3000 volumes: - ./config.json:/usr/src/app/config.json:ro # The application config (Must be created before starting the service) - - ./public:/usr/src/app/public:rw # Used for public facing images (uncomment if you are using your own images - see the public directory) + - ./public:/usr/src/app/public:rw # Used for public facing images (eg: avatar and background) diff --git a/start.sh b/start.sh index f8eff65..8a4125a 100644 --- a/start.sh +++ b/start.sh @@ -14,7 +14,7 @@ if [ -z "$(ls -A $workDir/public)" ]; then dir=$workDir/public/$item if [ ! -e "$dir" ]; then echo "Downloading $item to directory $dir" - wget -P $dir $baseUrl$item + wget -Pq $dir $baseUrl$item echo "Done" fi done From 692227f42081cbfedba362c9a799b0c417fc1451 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:38:42 +0100 Subject: [PATCH 12/13] fix wget command --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 8a4125a..ccc9dfe 100644 --- a/start.sh +++ b/start.sh @@ -14,7 +14,7 @@ if [ -z "$(ls -A $workDir/public)" ]; then dir=$workDir/public/$item if [ ! -e "$dir" ]; then echo "Downloading $item to directory $dir" - wget -Pq $dir $baseUrl$item + wget -q -P $dir $baseUrl$item echo "Done" fi done From d6122ff4048a306fa229fbeab90cc3489d4c8be3 Mon Sep 17 00:00:00 2001 From: Fascinated Date: Wed, 12 Jul 2023 14:42:14 +0100 Subject: [PATCH 13/13] bump version --- package.json | 2 +- start.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7be3b41..50ff9b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "simple-links", - "version": "0.1.6", + "version": "0.1.7", "private": false, "scripts": { "dev": "next dev", diff --git a/start.sh b/start.sh index ccc9dfe..8175ba4 100644 --- a/start.sh +++ b/start.sh @@ -7,6 +7,7 @@ echo "Checking if files need to be downloaded" if [ -z "$(ls -A $workDir/public)" ]; then echo "Some files are missing, downloading them" if [ ! -w "$workDir" ]; then + # TODO: fix this. it doesn't seem to be working? echo "The directory \"$workDir\" is not writeable, unable to download files. Please check your docker compose for :ro and set it to :rw" fi for item in "${toDownload[@]}"