diff --git a/Dockerfile b/Dockerfile index 4758522..3b0b10e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,9 @@ FROM node:lts-slim ENV NODE_ENV=production WORKDIR /usr/src/app +RUN apt update +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 ./ COPY package-lock.json ./ @@ -24,4 +27,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/docker-compose.yml b/docker-compose.yml index 14f76ad..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: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 (eg: avatar and background) 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 new file mode 100644 index 0000000..8175ba4 --- /dev/null +++ b/start.sh @@ -0,0 +1,28 @@ +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 $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[@]}" + do + dir=$workDir/public/$item + if [ ! -e "$dir" ]; then + echo "Downloading $item to directory $dir" + wget -q -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..." +npm start \ No newline at end of file