Skip to content

Commit 00480f2

Browse files
committed
fix: misc fixes to download function
1 parent aa7a69c commit 00480f2

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/__tests__/download.test.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,21 @@ describe('download module test suite', () => {
174174
)
175175
);
176176
expect(exec.logExecSync).toHaveBeenCalledWith(
177-
'sudo ln -s /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd'
177+
'sudo ln -sf /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd'
178178
);
179179
});
180180
test('should install cri-dockerd service', async () => {
181+
// Given
182+
fs.readFileSync.mockImplementation(
183+
() =>
184+
'ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://'
185+
);
181186
// When
182187
await download.installCriDockerd({githubToken: 'secret-token'});
183188
// Then
184-
expect(exec.logExecSync).toHaveBeenCalledWith(
185-
expect.stringMatching(
186-
/sed -i 's\/cri-dockerd --\/cri-dockerd --network-plugin=cni --\/g'/
187-
)
189+
expect(fs.writeFileSync).toHaveBeenCalledWith(
190+
'/etc/systemd/system/cri-docker.service',
191+
'ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --container-runtime-endpoint fd://'
188192
);
189193
expect(exec.logExecSync).toHaveBeenCalledWith(
190194
expect.stringMatching(

src/download.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ const installCriDockerd = async (inputs = {}) => {
7373
const binaryDir = await tc.extractTar(binaryTar);
7474
const binaryContent = firstDir(binaryDir);
7575
logExecSync(`sudo cp -a ${binaryDir}/${binaryContent}/cri-dockerd /usr/local/bin/`);
76-
logExecSync(`sudo ln -s /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd`);
76+
logExecSync(`sudo ln -sf /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd`);
7777
// Service file
7878
const sourceTar = await tc.downloadTool(`https://github.com/Mirantis/cri-dockerd/archive/refs/tags/${tag}.tar.gz`);
7979
const sourceDir = await tc.extractTar(sourceTar);
8080
const sourceContent = firstDir(sourceDir);
81-
logExecSync(`sed -i 's/cri-dockerd --/cri-dockerd --network-plugin=cni --/g' ${sourceDir}/${sourceContent}/packaging/systemd/cri-docker.service`);
8281
logExecSync(`sudo cp -a ${sourceDir}/${sourceContent}/packaging/systemd/* /etc/systemd/system`);
8382
const serviceFile = '/etc/systemd/system/cri-docker.service';
8483
fs.writeFileSync(serviceFile, fs.readFileSync(serviceFile).toString()
85-
.replace(/\/usr\/bin\/cri-dockerd/g, '/usr/local/bin/cri-dockerd')
84+
.replace(/cri-dockerd --/g, 'cri-dockerd --network-plugin=cni --')
8685
);
8786
const socketFile = '/etc/systemd/system/cri-docker.socket';
8887
fs.writeFileSync(socketFile, fs.readFileSync(socketFile).toString()

0 commit comments

Comments
 (0)