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 975d701
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/__tests__/download.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ 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
7 changes: 3 additions & 4 deletions src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ 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 --')
);
logExecSync(`sudo cp -a ${sourceDir}/${sourceContent}/packaging/systemd/* /etc/systemd/system`);
const socketFile = '/etc/systemd/system/cri-docker.socket';
fs.writeFileSync(socketFile, fs.readFileSync(socketFile).toString()
.replace(/cri-docker.sock/g, 'cri-dockerd.sock')
Expand Down

0 comments on commit 975d701

Please sign in to comment.