diff --git a/Dockerfile b/Dockerfile index 7e30a93..decbf32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,8 @@ FROM node:alpine RUN apk add git WORKDIR /service -RUN git clone https://gitea.frontblock.me/fb-dist/admin.git . +COPY dist /service/dist COPY node_modules /service/node_modules EXPOSE 8080 20000 -ENTRYPOINT ["node", "FrontblockAdmin.js"] \ No newline at end of file +ENTRYPOINT ["node", "dist/FrontblockAdmin.js"] \ No newline at end of file diff --git a/src/backend/GitUpdater.ts b/src/backend/GitUpdater.ts index 231c83b..0f0a410 100644 --- a/src/backend/GitUpdater.ts +++ b/src/backend/GitUpdater.ts @@ -27,6 +27,7 @@ const rmrf = (path:string, options = {}) => { export type RepoFolderStatus = { exists: boolean empty: boolean + isRepo: boolean currentTag?: string tags?: string[] latestTag?: string @@ -34,11 +35,8 @@ export type RepoFolderStatus = { } export class GitUpdater{ - private readonly repo + private repo: git.SimpleGit constructor(private readonly folderPath:string){ - this.folderPath = folderPath; - mkdirSync(this.folderPath, { recursive: true }); - this.repo = git(this.folderPath) } async getStatus():Promise{ @@ -46,7 +44,15 @@ export class GitUpdater{ await fs.access(this.folderPath); } catch (e) { - return { exists: false, empty: true }; + try{ + await gyt.gitDescribe(this.folderPath, { match: "*" }); + }catch(e2){ + return { exists: false, empty: true, isRepo: false }; + } + } + + if(!this.repo){ + this.repo = git(this.folderPath) } const files = await fs.readdir(this.folderPath) @@ -55,16 +61,18 @@ export class GitUpdater{ await this.repo.fetch("origin", "master", { "--tags": null }); - const remoteInfo = await this.repo.getRemotes(true) + const remoteInfo = await this.repo.getRemotes(/* verbose for full url */true) let remoteURL if(remoteInfo.length != 0){ - remoteURL = remoteInfo.find(i => i.name === "origin").refs.fetch + const filtered = remoteInfo.find(i => i.name === "origin") + remoteURL = filtered?filtered.refs.fetch:"origin unknown" } const remoteTags = await this.repo.tags(); const desc = await gyt.gitDescribe(this.folderPath, { match: "*" }); return { exists: true, empty: empty, + isRepo: true, currentTag: !desc.tag?null:desc.tag, tags: !remoteTags.all?[]:remoteTags.all, latestTag: remoteTags.latest, @@ -75,16 +83,19 @@ export class GitUpdater{ async cloneRepo(from:string, force:boolean = false):Promise { if(force){ await rmrf(this.folderPath) - await fs.mkdir(this.folderPath, { recursive: true }); + await fs.mkdir(this.folderPath) } const status = await this.getStatus() - if(!status.exists || !status.empty){ - logger.error("The folder "+this.folderPath+" doesn't exist or is not empty. Not cloning! Pass the force parameter to override this check") + if(!status.exists){ + await fs.mkdir(this.folderPath) + } + if(!status.empty){ + logger.error("The folder "+this.folderPath+" is not empty. Not cloning! Pass the force parameter to override this check") logger.error(status) return status } - await git(this.folderPath).clone(from, path.resolve(this.folderPath)); + await git().clone(from, path.resolve(this.folderPath)); return await this.getStatus(); } @@ -97,4 +108,4 @@ export class GitUpdater{ await this.repo.checkout(tag); return await this.getStatus(); } -} +} \ No newline at end of file