Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve some lando4 service things #172

Merged
merged 4 commits into from
May 25, 2024
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
12 changes: 6 additions & 6 deletions builders/lando-v4.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = {

// build script
// @TODO: handle array content?
this.buildScript = config?.build?.app ?? `true`;
this.buildScript = config?.build?.app ?? false;

// set some other stuff
if (config['app-mount']) this.setAppMount(config['app-mount']);
Expand All @@ -136,12 +136,12 @@ module.exports = {
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
`});

// inject global npmrc if we can

// add a home folder persistent mount
this.addComposeData({volumes: {[this.homevol]: {external: true}}});
this.addComposeData({volumes: {[this.homevol]: {}}});
// add the usual DC stuff
this.addServiceData({user: config.user ?? this.username, volumes: [`${this.homevol}:/home/${this.username}`]});
// add build vols
this.addAppBuildVolume(`${this.homevol}:/home/${this.username}`);
}

addAppBuildVolume(volumes) {
Expand All @@ -156,7 +156,7 @@ module.exports = {
async buildApp() {
// bail if no script
if (!this.buildScript) {
this.debug('no build detected, skipping');
this.debug(`no build detected for ${this.id}, skipping`);
return;
};

Expand Down Expand Up @@ -187,7 +187,7 @@ module.exports = {
const command = `chmod +x ${bs} && sh ${bs}`;

// add build vols
this.addAppBuildVolume([`${buildScriptPath}:${bs}`, `${this.homevol}:/home/${this.username}`]);
this.addAppBuildVolume(`${buildScriptPath}:${bs}`);

// run with the appropriate builder
const success = await bengine.run([command], {
Expand Down
64 changes: 33 additions & 31 deletions utils/generate-build-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,40 @@

module.exports = (contents, user, gid, socket, mount = '/app') => `
#!/bin/sh

retry_with_backoff() {
local max_attempts=\${MAX_ATTEMPTS-10}
local initial_delay=\${INITIAL_DELAY-1}
local factor=\${FACTOR-2}
local attempt=1
local delay=$initial_delay

while true; do
"$@"
local status=$?
if [ $status -eq 0 ]; then
return 0
fi

if [ $attempt -ge $max_attempts ]; then
echo "Attempt $attempt failed and there are no more attempts left!"
return $status
fi

echo "Attempt $attempt failed! Retrying in $delay seconds..."
sleep $delay
attempt=$((attempt + 1))
delay=$((delay * factor))
done
}

# clean up and setup ssh-auth
if [ -S "${socket}" ]; then
rm -rf /run/ssh-${user}.sock
sudo socat UNIX-LISTEN:/run/ssh-${user}.sock,fork,user=${user},group=${gid},mode=777 UNIX-CONNECT:${socket} &
sleep 2
if command -v socat >/dev/null 2>&1 && command -v sudo >/dev/null 2>&1; then
if [ -S "${socket}" ]; then
rm -rf /run/ssh-${user}.sock
sudo socat UNIX-LISTEN:/run/ssh-${user}.sock,fork,user=${user},group=${gid},mode=777 UNIX-CONNECT:${socket} &
retry_with_backoff ssh-add -l > /dev/null 2>&1;
fi
fi

# temp stuff for demo purposes
Expand All @@ -17,30 +46,3 @@ fi

${contents}
`;

/*
# Timeout period in seconds
TIMEOUT=30
# Time interval between checks in seconds
INTERVAL=1
# Start time
START_TIME=$(date +%s)
# wait until socket is ready
while true; do
# Check if ssh-agent is running
if ssh-add -l > /dev/null 2>&1; then
break
fi

# Check if the timeout period has been reached
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if [ $ELAPSED_TIME -ge $TIMEOUT ]; then
echo "Timeout reached. ssh-agent is not ready."
exit 1
fi

# Wait for the specified interval before checking again
sleep $INTERVAL
done
*/
Loading