diff --git a/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts b/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts index 3ed2be0..432fac0 100644 --- a/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts +++ b/src/modules/qqbot/napcat/infrastructure/integration/container/qqbot-napcat-container.service.ts @@ -1402,7 +1402,12 @@ docker logs --since "$SINCE" --tail 300 "$NAME" 2>&1 || true const passwordRunFlag = loginPassword ? ' -e NAPCAT_QUICK_PASSWORD="$NAPCAT_QUICK_PASSWORD" \\\n' : ''; - const pullCmd = input.skipPull ? '' : 'docker pull "$IMAGE" >/dev/null\n'; + const pullCmd = input.skipPull + ? '' + : `if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then + docker pull "$IMAGE" >/dev/null +fi +`; const deviceHeader = input.deviceIdentity ? [ `NAPCAT_HOSTNAME=${this.sh(input.deviceIdentity.hostname)}`, diff --git a/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts b/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts index 82773b0..b3e0c5e 100644 --- a/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts +++ b/test/qqbot/napcat/qqbot-napcat-container.service.spec.ts @@ -436,7 +436,7 @@ describe('QqbotNapcatContainerService', () => { expect(withoutAccount).not.toContain('NAPCAT_QUICK_PASSWORD'); }); - it('skips docker pull when recreating in place for quick login', () => { + it('checks the local image before pulling when creating a container', () => { const service = new QqbotNapcatContainerService( { get: jest.fn().mockReturnValue('') } as any, {} as any, @@ -453,10 +453,21 @@ describe('QqbotNapcatContainerService', () => { token: 'token-test', }; - expect(service.buildRemoteCreateScript(baseInput)).toContain('docker pull'); - expect( - service.buildRemoteCreateScript({ ...baseInput, skipPull: true }), - ).not.toContain('docker pull'); + const createScript = service.buildRemoteCreateScript(baseInput); + expect(createScript).toContain( + 'if ! docker image inspect "$IMAGE" >/dev/null 2>&1; then', + ); + expect(createScript).toContain('docker pull "$IMAGE" >/dev/null'); + expect(createScript.indexOf('docker image inspect')).toBeLessThan( + createScript.indexOf('docker pull "$IMAGE"'), + ); + + const quickLoginScript = service.buildRemoteCreateScript({ + ...baseInput, + skipPull: true, + }); + expect(quickLoginScript).not.toContain('docker image inspect "$IMAGE"'); + expect(quickLoginScript).not.toContain('docker pull'); }); it('generates Chinese desktop runtime flags and account config files', () => {