فهرست منبع

fix: clone scripts

Nicolas Meienberger 2 سال پیش
والد
کامیت
1cb2a37e25

+ 2 - 1
docker-compose.dev.yml

@@ -15,7 +15,7 @@ services:
       POSTGRES_USER: tipi
       POSTGRES_DB: tipi
     healthcheck:
-      test: [ "CMD-SHELL", "pg_isready -d tipi -U tipi" ]
+      test: ["CMD-SHELL", "pg_isready -d tipi -U tipi"]
       interval: 5s
       timeout: 10s
       retries: 120
@@ -50,6 +50,7 @@ services:
       POSTGRES_DBNAME: tipi
       POSTGRES_HOST: tipi-db
       APPS_REPO_ID: ${APPS_REPO_ID}
+      APPS_REPO_URL: ${APPS_REPO_URL}
     networks:
       - tipi_main_network
 

+ 2 - 1
docker-compose.rc.yml

@@ -29,7 +29,7 @@ services:
       POSTGRES_USER: tipi
       POSTGRES_DB: tipi
     healthcheck:
-      test: [ "CMD-SHELL", "pg_isready -d tipi -U tipi" ]
+      test: ["CMD-SHELL", "pg_isready -d tipi -U tipi"]
       interval: 5s
       timeout: 10s
       retries: 120
@@ -61,6 +61,7 @@ services:
       POSTGRES_HOST: tipi-db
       NODE_ENV: production
       APPS_REPO_ID: ${APPS_REPO_ID}
+      APPS_REPO_URL: ${APPS_REPO_URL}
     dns:
       - ${DNS_IP}
     networks:

+ 2 - 1
docker-compose.yml

@@ -29,7 +29,7 @@ services:
       POSTGRES_USER: tipi
       POSTGRES_DB: tipi
     healthcheck:
-      test: [ "CMD-SHELL", "pg_isready -d tipi -U tipi" ]
+      test: ["CMD-SHELL", "pg_isready -d tipi -U tipi"]
       interval: 5s
       timeout: 10s
       retries: 120
@@ -62,6 +62,7 @@ services:
       POSTGRES_HOST: tipi-db
       NODE_ENV: production
       APPS_REPO_ID: ${APPS_REPO_ID}
+      APPS_REPO_URL: ${APPS_REPO_URL}
     dns:
       - ${DNS_IP}
     networks:

+ 3 - 0
packages/system-api/src/config/config.ts

@@ -13,6 +13,7 @@ interface IConfig {
   VERSION: string;
   ROOT_FOLDER_HOST: string;
   APPS_REPO_ID: string;
+  APPS_REPO_URL: string;
 }
 
 if (process.env.NODE_ENV !== 'production') {
@@ -32,6 +33,7 @@ const {
   ROOT_FOLDER_HOST = '',
   NGINX_PORT = '80',
   APPS_REPO_ID = '',
+  APPS_REPO_URL = '',
 } = process.env;
 
 const config: IConfig = {
@@ -47,6 +49,7 @@ const config: IConfig = {
   VERSION: TIPI_VERSION,
   ROOT_FOLDER_HOST,
   APPS_REPO_ID,
+  APPS_REPO_URL,
 };
 
 export default config;

+ 1 - 1
packages/system-api/src/core/jobs/jobs.ts

@@ -8,7 +8,7 @@ const startJobs = () => {
 
   cron.schedule('0 * * * *', () => {
     logger.info('Cloning apps repo...');
-    updateRepo(config.APPS_REPO_ID);
+    updateRepo(config.APPS_REPO_URL);
   });
 };
 

+ 2 - 3
packages/system-api/src/helpers/repo-helpers.ts

@@ -1,9 +1,8 @@
-import config from '../config';
 import { runScript } from '../modules/fs/fs.helpers';
 
 export const updateRepo = (repo: string): Promise<void> => {
   return new Promise((resolve, reject) => {
-    runScript('/scripts/git.sh', ['update', repo, config.ROOT_FOLDER_HOST], (err: string, stdout: string) => {
+    runScript('/scripts/git.sh', ['update', repo], (err: string, stdout: string) => {
       if (err) {
         reject(err);
       }
@@ -17,7 +16,7 @@ export const updateRepo = (repo: string): Promise<void> => {
 
 export const cloneRepo = (repo: string): Promise<void> => {
   return new Promise((resolve, reject) => {
-    runScript('/scripts/git.sh', ['clone', repo, config.ROOT_FOLDER_HOST], (err: string, stdout: string) => {
+    runScript('/scripts/git.sh', ['clone', repo], (err: string, stdout: string) => {
       if (err) {
         reject(err);
       }

+ 2 - 1
packages/system-api/src/modules/fs/fs.helpers.ts

@@ -43,7 +43,8 @@ export const getSeed = () => {
 };
 
 export const ensureAppFolder = (appName: string) => {
-  if (!fileExists(`/apps/${appName}`)) {
+  if (!fileExists(`/apps/${appName}/docker-compose.yml`)) {
+    fs.removeSync(getAbsolutePath(`/apps/${appName}`));
     // Copy from apps repo
     fs.copySync(getAbsolutePath(`/repos/${config.APPS_REPO_ID}/apps/${appName}`), getAbsolutePath(`/apps/${appName}`));
   }

+ 2 - 2
packages/system-api/src/server.ts

@@ -74,8 +74,8 @@ const main = async () => {
     await runUpdates();
 
     httpServer.listen(port, async () => {
-      await cloneRepo(config.APPS_REPO_ID);
-      await updateRepo(config.APPS_REPO_ID);
+      await cloneRepo(config.APPS_REPO_URL);
+      await updateRepo(config.APPS_REPO_URL);
       startJobs();
       // Start apps
       appsService.startAllApps();

+ 6 - 4
scripts/git.sh

@@ -39,8 +39,9 @@ fi
 # Clone a repo
 if [[ "$command" = "clone" ]]; then
     repo="$2"
-    echo "Cloning ${repo} to ${ROOT_FOLDER}/repos/${repo}"
-    repo_dir="${ROOT_FOLDER}/repos/${repo}"
+    repo_hash=$(get_hash "${repo}")
+    echo "Cloning ${repo} to ${ROOT_FOLDER}/repos/${repo_hash}"
+    repo_dir="${ROOT_FOLDER}/repos/${repo_hash}"
     if [ -d "${repo_dir}" ]; then
         echo "Repo already exists"
         exit 0
@@ -55,13 +56,14 @@ fi
 # Update a repo
 if [[ "$command" = "update" ]]; then
     repo="$2"
-    repo_dir="${ROOT_FOLDER}/repos/${repo}"
+    repo_hash=$(get_hash "${repo}")
+    repo_dir="${ROOT_FOLDER}/repos/${repo_hash}"
     if [ ! -d "${repo_dir}" ]; then
         echo "Repo does not exist"
         exit 0
     fi
 
-    echo "Updating ${repo} in ${repo_dir}"
+    echo "Updating ${repo} in ${repo_hash}"
     cd "${repo_dir}"
     git pull origin master
     echo "Done"

+ 2 - 1
scripts/start.sh

@@ -68,8 +68,8 @@ DNS_IP=9.9.9.9 # Default to Quad9 DNS
 ARCHITECTURE="$(uname -m)"
 TZ="$(timedatectl | grep "Time zone" | awk '{print $3}' | sed 's/\//\\\//g' || Europe\/Berlin)"
 APPS_REPOSITORY="https://github.com/meienberger/runtipi-appstore"
-APPS_REPOSITORY="https://github.com/meienberger/runtipi-appstore"
 REPO_ID="$(${ROOT_FOLDER}/scripts/git.sh get_hash ${APPS_REPOSITORY})"
+APPS_REPOSITORY_ESCAPED="$(echo ${APPS_REPOSITORY} | sed 's/\//\\\//g')"
 
 if [[ "$ARCHITECTURE" == "aarch64" ]]; then
   ARCHITECTURE="arm64"
@@ -153,6 +153,7 @@ for template in ${ENV_FILE}; do
   sed -i "s/<proxy_port>/${PROXY_PORT}/g" "${template}"
   sed -i "s/<postgres_password>/${POSTGRES_PASSWORD}/g" "${template}"
   sed -i "s/<apps_repo_id>/${REPO_ID}/g" "${template}"
+  sed -i "s/<apps_repo_url>/${APPS_REPOSITORY_ESCAPED}/g" "${template}"
 done
 
 mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"

+ 1 - 0
templates/env-sample

@@ -2,6 +2,7 @@
 # It will be overwritten on update.
 
 APPS_REPO_ID=<apps_repo_id>
+APPS_REPO_URL=<apps_repo_url>
 TZ=<tz>
 INTERNAL_IP=<internal_ip>
 DNS_IP=<dns_ip>