Skip to content

Commit

Permalink
doker login from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
pitiscarf committed Nov 6, 2024
1 parent 29e0fa2 commit ff06054
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/wip-deploy-ci-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ jobs:
with:
node-version: "18.20"

- name: Login to Docker Container Registry
uses: docker/login-action@v2
with:
username: nologin
password: ${{ secrets.SCW_CI_DEPLOY_SECRET_KEY }}
registry: rg.fr-par.scw.cloud/snu-ci

- name: Docker Build & Publish
working-directory: devops/scripts
env:
Expand Down
8 changes: 7 additions & 1 deletion devops/scripts/build-front-app-docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const UserInput = require("./lib/user-input");
const ScalewayClient = require("./lib/scaleway-client");
const { GetSecrets, SECRET_FORMATS } = require("./get-secrets");
const { getConfig } = require("./lib/config");
const { childProcess } = require("./lib/utils");
const { childProcess, childProcessStdin } = require("./lib/utils");

const SECRET_KEYS = new Set(["SENTRY_AUTH_TOKEN"]);
const RELEASE_KEY = "VITE_RELEASE";
Expand Down Expand Up @@ -63,6 +63,12 @@ async function main() {
await childProcess("docker", args, { env });

if (input.push) {
await childProcessStdin(
"docker",
["login", registry, "-u", "nologin", "--password-stdin"],
input.SCW_SECRET_KEY,
{ env }
);
await childProcess("docker", ["push", image], { env });
}
}
Expand Down
23 changes: 23 additions & 0 deletions devops/scripts/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ function childProcess(command, args, options) {
});
}

function childProcessStdin(command, args, input, options) {
let proc = spawn(command, args, {
stdio: ["pipe", "inherit", "inherit"],
cwd: path.resolve(__dirname, "../../.."), // Project root directory
...options,
});
return new Promise((resolve, reject) => {
proc.on("spawn", () => {
proc.stdin.write(input);
proc.stdin.end();
});
proc.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`ChildProcess exited with status ${code}`));
}
});
proc.on("error", reject);
});
}

async function genericDeleteAll({
items,
name,
Expand Down Expand Up @@ -83,4 +105,5 @@ module.exports = {
genericDeleteAll,
environmentFromBranch,
childProcess,
childProcessStdin,
};

0 comments on commit ff06054

Please sign in to comment.