-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automate docker and dos2unix installation in ec2
- Loading branch information
1 parent
7437fe0
commit e4e1863
Showing
3 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { NodeSSH } from 'node-ssh'; | ||
|
||
export async function installDos2unix(ssh: NodeSSH) { | ||
console.log('Installing dos2unix...'); | ||
const result = await ssh.execCommand( | ||
'sudo apt-get update && sudo apt-get install -y dos2unix' | ||
); | ||
if (result.code !== 0) { | ||
console.error('Failed to install dos2unix:', result.stderr); | ||
throw new Error('Failed to install dos2unix'); | ||
} | ||
console.log('dos2unix installed successfully.'); | ||
} | ||
|
||
export async function installDocker(ssh: NodeSSH) { | ||
console.log('Installing Docker...'); | ||
const commands = [ | ||
'sudo apt-get update', | ||
'sudo apt-get install -y ca-certificates curl', | ||
'sudo install -m 0755 -d /etc/apt/keyrings', | ||
'sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc', | ||
'sudo chmod a+r /etc/apt/keyrings/docker.asc', | ||
'echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null', | ||
'sudo apt-get update', | ||
'sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin', | ||
]; | ||
|
||
for (const command of commands) { | ||
const result = await ssh.execCommand(command); | ||
if (result.code !== 0) { | ||
console.error(`Failed to execute command: ${command}`); | ||
console.error('Error:', result.stderr); | ||
throw new Error('Failed to install Docker'); | ||
} | ||
} | ||
console.log('Docker installed successfully.'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters