Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions scripts/vssh-motor-publish
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
# `VSSH_SITIO_S3_SECRET_ACCESS_KEY`, de um Secret do cluster), e o CI do app não guarda chave de
# sítio nenhuma.
#
# A subida usa o `aws` do PATH; sem ele, o container `amazon/aws-cli`; sem docker, o `awscli` do
# PyPI pelo `uvx`, com o `uv` baixado do release quando não está no PATH. O runner de um sítio não
# tem `sudo` nem docker. Só biblioteca padrão do Python para mexer no manifesto, como o
# A subida usa o `aws` do PATH; sem ele, o container `amazon/aws-cli`, quando o docker responde; sem
# isso, o `awscli` do PyPI pelo `uvx`, com o `uv` baixado do release quando não está no PATH. A
# imagem dos runners da casa traz o cliente do docker, e o runner de motor de um sítio não tem o
# daemon: o cliente no PATH sozinho não basta. Só biblioteca padrão do Python para mexer no manifesto, como o
# `vssh-app-publish`.
set -euo pipefail

Expand Down Expand Up @@ -133,7 +134,7 @@ export AWS_ACCESS_KEY_ID="${CHAVE_ID}" AWS_SECRET_ACCESS_KEY="${SEGREDO}" AWS_DE
export AWS_REQUEST_CHECKSUM_CALCULATION=when_required AWS_RESPONSE_CHECKSUM_VALIDATION=when_required
if command -v aws >/dev/null 2>&1; then
aws s3 cp "${ARQUIVO}" "s3://${BUCKET}/${CHAVE}" --endpoint-url "${ENDPOINT}" --content-type application/gzip
elif command -v docker >/dev/null 2>&1; then
elif command -v docker >/dev/null 2>&1 && docker info >/dev/null 2>&1; then
dir_tar="$(cd "$(dirname "${ARQUIVO}")" && pwd)"
docker run --rm \
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION \
Expand Down
27 changes: 27 additions & 0 deletions tests/publish-motor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,33 @@ test('o pino grava o nome público do repositório quando a publicação vai pel
} finally { await r.fechar(); }
});

test('com o cliente do docker e sem o daemon, a subida vai pelo uvx', pular, async () => {
const r = await repo();
try {
const b = bancada(APP);
// Sem o aws: o PATH desta bancada tem só o docker sem daemon e o uvx, que faz o papel do aws.
fs.rmSync(path.join(b.bin, 'aws'));
fs.writeFileSync(path.join(b.bin, 'docker'), '#!/bin/bash\n[ "$1" = info ] && exit 1\necho "docker run não devia ser chamado" >&2; exit 9\n', { mode: 0o755 });
fs.writeFileSync(path.join(b.bin, 'uvx'), `#!/bin/bash
# uvx --from <pacote> aws s3 cp <arquivo> s3://<bucket>/<chave> ...
shift 2; shift
printf '%s\\n' "$@" > "${b.bucket}/argumentos"
destino="\${4#s3://}"
mkdir -p "${b.bucket}/$(dirname "$destino")"
cp "$3" "${b.bucket}/$destino"
`, { mode: 0o755 });
const semAws = process.env.PATH.split(':').filter((d) => !fs.existsSync(path.join(d, 'aws'))).join(':');
const s = await publicar(b, r.base, ['--nome', 'runtime', '--versao', '1.1', '--arquivo', b.tarball, '--sem-pino'], {
PATH: `${b.bin}:${semAws}`,
R2_ACCOUNT_ID: '', R2_ACCESS_KEY_ID: '', R2_SECRET_ACCESS_KEY: '',
S3_ENDPOINT: 'http://seaweedfs-s3.seaweedfs.svc.cluster.local:8333', S3_ACCESS_KEY_ID: 'ci', S3_SECRET_ACCESS_KEY: 'segredo',
});
assert.equal(s.code, 0, s.saida);
assert.ok(fs.existsSync(path.join(b.bucket, 'vssh-repo', 'motor/escriba-runtime/1.1/motor.tar.gz')), s.saida);
assert.equal(r.registros.length, 1);
} finally { await r.fechar(); }
});

test('um registro recusado não toca no manifesto', pular, async () => {
const r = await repo(409);
try {
Expand Down