Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(build): read git, ssh and scp ADD sources as remote in the gate
Yudhi Armyndharis47e4e2346f15
diff --git a/scripts/check-dockerignore.mjs b/scripts/check-dockerignore.mjsindex 34b964716..4ecb66823 100644--- a/scripts/check-dockerignore.mjs+++ b/scripts/check-dockerignore.mjs@@ -179,10 +179,14 @@ const dockerfile = readFileSync(new URL('Dockerfile', root), 'utf8').join('\n').replace(/\\[ \t\r]*\n(?:[ \t\r]*\n)*/g, ' ');const wildcard = /[*?[]/;+// user@host:path as BuildKit takes it: a user of letters, digits, _ and -, and a host of letters, digits, . and -+// or an IPv6 address in brackets.+const SCP_ADDRESS = /^[A-Za-z0-9_-]+@(?:[A-Za-z0-9.-]+|\[[0-9A-Fa-f:.]+\]):/;function copyInputs(source) {- // Remote, as in BuildKit: an http(s) URL or a git reference, in lower case. ADD ftp://x/y, s3://x/y,- // file:///x and HTTPS://x/y name context paths.- if (/^(?:https?|git|ssh):\/\/|^git@/.test(source)) return [];+ // Remote, as BuildKit 0.34 reads it: an http(s) URL in lower case, a git:// or ssh:// URL in any case, or an+ // scp address user@host:path. Anything else, ftp://x/y, s3://x/y, file:///x, HTTPS://x/y or user@host, names+ // a context path.+ if (/^https?:\/\//.test(source) || /^(?:git|ssh):\/\//i.test(source) || SCP_ADDRESS.test(source)) return [];// Docker resolves ./x, /x and x//y against the context root, which is the form the rules match.const path = posix.normalize(source).replace(/^\/+|\/+$/g, '');if (path === '' || path === '.') return [];diff --git a/scripts/check-dockerignore.spec.mjs b/scripts/check-dockerignore.spec.mjsindex 4099197cd..a47effd3e 100644--- a/scripts/check-dockerignore.spec.mjs+++ b/scripts/check-dockerignore.spec.mjs@@ -210,15 +210,46 @@ test('? and [..] in a COPY source are wildcards of the file name', () => {}});-test('only an http(s) URL or a git reference is a remote ADD source, any other scheme names a context path', () => {- // Real BuildKit fetches ADD http://, https://, git://, ssh:// and git@ sources. It looks in the context for- // anything else: ftp:// is the file ftp:/host/x.tgz, file:///x.tgz is file:/x.tgz, and a scheme that is not in- // lower case, HTTPS://host/x.tgz, is HTTPS:/host/x.tgz.+test('an http(s) URL in lower case, a git:// or ssh:// URL in any case and a user@host:path are remote ADD sources', () => {+ // Real BuildKit 0.34 fetches these, so the context is not read for them and a rule that happens to match their+ // text drops nothing the build needs.+ const remote = [+ 'http://example.com/x.tgz',+ 'https://example.com/x.tgz',+ 'git://example.com/org/repo.git',+ 'GIT://example.com/org/repo.git',+ 'Git://example.com/org/repo.git',+ 'ssh://[email protected]/org/repo.git',+ 'SSH://[email protected]/org/repo.git',+ '[email protected]:org/repo.git',+ '[email protected]:org/repo.git',+ '[email protected]:org/repo.git',+ 'deploy@[::1]:org/repo.git',+ ];+ for (const source of remote) {+ const run = runGate({+ Dockerfile: `COPY control.txt ./\nADD ${source} /opt/\n`,+ // Matches the text of every source above, mangled into a context path or not.+ '.dockerignore': `${REAL_DOCKERIGNORE}\n**/*.git\n**/*.tgz\n`,+ });+ assert.equal(run.status, 0, `ADD ${source} was read as a context file: ${run.out}`);+ }+});++test('any other ADD source names a context path: ftp://, s3://, file:///, a scheme that is not in lower case, user@host', () => {+ // The same BuildKit looks in the context for these. ftp://host/x.tgz is the file ftp:/host/x.tgz, file:///x.tgz is+ // file:/x.tgz, HTTPS://host/x.tgz is HTTPS:/host/x.tgz, and user@host:path needs a user of letters, digits, _ and+ // - and a host of letters, digits, . and - to be an scp address, or it is the file of that name.const contextPaths = [['ftp://example.com/x.tgz', 'ftp:/example.com/x.tgz'],['s3://example.com/x.tgz', 's3:/example.com/x.tgz'],['file:///x.tgz', 'file:/x.tgz'],['HTTPS://example.com/x.tgz', 'HTTPS:/example.com/x.tgz'],+ ['HTTP://example.com/x.tgz', 'HTTP:/example.com/x.tgz'],+ ['[email protected]:x.tgz', '[email protected]:x.tgz'],+ ['user@ho_st:x.tgz', 'user@ho_st:x.tgz'],+ ['[email protected]', '[email protected]'],+ ['dir/[email protected]:x.tgz', 'dir/[email protected]:x.tgz'],];for (const [source, path] of contextPaths) {const run = runGate({@@ -260,6 +291,9 @@ test('only the context files a COPY or ADD reads are build inputs', () => {'ADD git://example.com/org/repo.git /opt/repo','ADD ssh://[email protected]/org/repo.git /opt/repo','ADD [email protected]:org/repo.git /opt/repo',+ 'ADD [email protected]:org/repo.git /opt/repo',+ 'ADD GIT://example.com/org/upper.git /opt/repo',+ 'ADD SSH://[email protected]/org/upper.git /opt/repo','COPY . .','COPY ./ ./','COPY / ./',