Skip to content

Commit

Permalink
fix: misc fixes to download function
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Dec 23, 2022
1 parent aa7a69c commit 00480f2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/__tests__/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,21 @@ describe('download module test suite', () => {
)
);
expect(exec.logExecSync).toHaveBeenCalledWith(
'sudo ln -s /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd'
'sudo ln -sf /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd'
);
});
test('should install cri-dockerd service', async () => {
// Given
fs.readFileSync.mockImplementation(
() =>
'ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://'
);
// When
await download.installCriDockerd({githubToken: 'secret-token'});
// Then
expect(exec.logExecSync).toHaveBeenCalledWith(
expect.stringMatching(
/sed -i 's\/cri-dockerd --\/cri-dockerd --network-plugin=cni --\/g'/
)
expect(fs.writeFileSync).toHaveBeenCalledWith(
'/etc/systemd/system/cri-docker.service',
'ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --container-runtime-endpoint fd://'
);
expect(exec.logExecSync).toHaveBeenCalledWith(
expect.stringMatching(
Expand Down
5 changes: 2 additions & 3 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,15 @@ const installCriDockerd = async (inputs = {}) => {
const binaryDir = await tc.extractTar(binaryTar);
const binaryContent = firstDir(binaryDir);
logExecSync(`sudo cp -a ${binaryDir}/${binaryContent}/cri-dockerd /usr/local/bin/`);
logExecSync(`sudo ln -s /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd`);
logExecSync(`sudo ln -sf /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd`);
// Service file
const sourceTar = await tc.downloadTool(`https://github.com/Mirantis/cri-dockerd/archive/refs/tags/${tag}.tar.gz`);
const sourceDir = await tc.extractTar(sourceTar);
const sourceContent = firstDir(sourceDir);
logExecSync(`sed -i 's/cri-dockerd --/cri-dockerd --network-plugin=cni --/g' ${sourceDir}/${sourceContent}/packaging/systemd/cri-docker.service`);
logExecSync(`sudo cp -a ${sourceDir}/${sourceContent}/packaging/systemd/* /etc/systemd/system`);
const serviceFile = '/etc/systemd/system/cri-docker.service';
fs.writeFileSync(serviceFile, fs.readFileSync(serviceFile).toString()
.replace(/\/usr\/bin\/cri-dockerd/g, '/usr/local/bin/cri-dockerd')
.replace(/cri-dockerd --/g, 'cri-dockerd --network-plugin=cni --')
);
const socketFile = '/etc/systemd/system/cri-docker.socket';
fs.writeFileSync(socketFile, fs.readFileSync(socketFile).toString()
Expand Down

0 comments on commit 00480f2

Please sign in to comment.