Skip to content

Commit c863ef3

Browse files
author
Dani Llewellyn
authored
Merge pull request #7 from diddlesnaps/update-for-container-snapd-fix
Update for fixed container image's new command line
2 parents 63e1d7a + 2b41f95 commit c863ef3

File tree

14 files changed

+407
-986
lines changed

14 files changed

+407
-986
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ jobs:
2222
- core
2323
- core18
2424
- core20
25+
- core22
2526
arch:
2627
- ''
2728
- amd64
28-
- i386
2929
- armhf
3030
- arm64
3131
- ppc64el
32-
exclude:
33-
- base: core20
34-
arch: armhf
35-
- base: core20
32+
#exclude:
33+
# - base: core20
34+
# arch: armhf
35+
# - base: core22
36+
# arch: armhf
37+
include:
38+
- base: core
39+
arch: i386
40+
- base: core18
3641
arch: i386
3742
runs-on: ubuntu-latest
3843
steps:
3944
- uses: docker/setup-qemu-action@v1
40-
with:
41-
image: tonistiigi/binfmt@sha256:df15403e06a03c2f461c1f7938b171fda34a5849eb63a70e2a2109ed5a778bde
42-
- uses: actions/checkout@v2
45+
- uses: actions/checkout@v3
4346
- uses: ./
4447
id: snapcraft
4548
with:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ lib/**/*
101101
# Ignore backup files
102102
*~
103103
*.swp
104+
105+
test-projects/*/parts
106+
test-projects/*/stage
107+
test-projects/*/prime
108+
test-projects/*/*.snap

__tests__/build.test.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ for (const [base, arch, channel] of [
4545
['core20', 's390x', 'stable']
4646
]) {
4747
test(`SnapcraftBuilder.build runs a snap build with base: ${base}; and arch: ${arch}`, async () => {
48-
expect.assertions(4)
48+
expect.assertions(3)
4949

50-
const ensureDisabledAppArmorRulesMock = jest
51-
.spyOn(tools, 'ensureDisabledAppArmorRules')
52-
.mockImplementation(async (): Promise<void> => {})
5350
const ensureDockerExperimentalMock = jest
5451
.spyOn(tools, 'ensureDockerExperimental')
55-
.mockImplementation(async (): Promise<void> => {})
52+
.mockImplementation(async (): Promise<void> => Promise.resolve())
5653
const detectBaseMock = jest
5754
.spyOn(tools, 'detectBase')
58-
.mockImplementation(async (projectRoot: string): Promise<string> => base)
59-
const execMock = jest.spyOn(exec, 'exec').mockImplementation(
60-
async (program: string, args?: string[]): Promise<number> => {
61-
return 0
62-
}
63-
)
55+
.mockImplementation(
56+
async (projectRoot: string): Promise<string> => Promise.resolve(base)
57+
)
58+
const execMock = jest
59+
.spyOn(exec, 'exec')
60+
.mockImplementation(
61+
async (program: string, args?: string[]): Promise<number> => 0
62+
)
6463
process.env['GITHUB_REPOSITORY'] = 'user/repo'
6564
process.env['GITHUB_RUN_ID'] = '42'
6665

@@ -80,7 +79,6 @@ for (const [base, arch, channel] of [
8079
platform = ['--platform', build.platforms[arch]]
8180
}
8281

83-
expect(ensureDisabledAppArmorRulesMock).toHaveBeenCalled()
8482
expect(ensureDockerExperimentalMock).toHaveBeenCalled()
8583
expect(detectBaseMock).toHaveBeenCalled()
8684
expect(execMock).toHaveBeenCalledWith(
@@ -90,8 +88,6 @@ for (const [base, arch, channel] of [
9088
'--rm',
9189
'--tty',
9290
'--privileged',
93-
'--security-opt',
94-
'apparmor=:docker-snapcraft:unconfined',
9591
'--volume',
9692
`${process.cwd()}/${projectDir}:/data`,
9793
'--workdir',
@@ -118,22 +114,19 @@ for (const [base, arch, channel] of [
118114
test('SnapcraftBuilder.build can disable build info', async () => {
119115
expect.assertions(1)
120116

121-
const ensureDisabledAppArmorRulesMock = jest
122-
.spyOn(tools, 'ensureDisabledAppArmorRules')
123-
.mockImplementation(async (): Promise<void> => {})
124117
const ensureDockerExperimentalMock = jest
125118
.spyOn(tools, 'ensureDockerExperimental')
126-
.mockImplementation(async (): Promise<void> => {})
119+
.mockImplementation(async (): Promise<void> => Promise.resolve())
127120
const detectBaseMock = jest
128121
.spyOn(tools, 'detectBase')
129122
.mockImplementation(
130123
async (projectRoot: string): Promise<string> => default_base
131124
)
132-
const execMock = jest.spyOn(exec, 'exec').mockImplementation(
133-
async (program: string, args?: string[]): Promise<number> => {
134-
return 0
135-
}
136-
)
125+
const execMock = jest
126+
.spyOn(exec, 'exec')
127+
.mockImplementation(
128+
async (program: string, args?: string[]): Promise<number> => 0
129+
)
137130

138131
const builder = new build.SnapcraftBuilder('.', false, 'stable', '', '', '')
139132
await builder.build()
@@ -145,8 +138,6 @@ test('SnapcraftBuilder.build can disable build info', async () => {
145138
'--rm',
146139
'--tty',
147140
'--privileged',
148-
'--security-opt',
149-
'apparmor=:docker-snapcraft:unconfined',
150141
'--volume',
151142
`${process.cwd()}:/data`,
152143
'--workdir',
@@ -169,22 +160,19 @@ test('SnapcraftBuilder.build can disable build info', async () => {
169160
test('SnapcraftBuilder.build can pass additional arguments', async () => {
170161
expect.assertions(1)
171162

172-
const ensureDisabledAppArmorRulesMock = jest
173-
.spyOn(tools, 'ensureDisabledAppArmorRules')
174-
.mockImplementation(async (): Promise<void> => {})
175163
const ensureDockerExperimentalMock = jest
176164
.spyOn(tools, 'ensureDockerExperimental')
177-
.mockImplementation(async (): Promise<void> => {})
165+
.mockImplementation(async (): Promise<void> => Promise.resolve())
178166
const detectBaseMock = jest
179167
.spyOn(tools, 'detectBase')
180168
.mockImplementation(
181169
async (projectRoot: string): Promise<string> => default_base
182170
)
183-
const execMock = jest.spyOn(exec, 'exec').mockImplementation(
184-
async (program: string, args?: string[]): Promise<number> => {
185-
return 0
186-
}
187-
)
171+
const execMock = jest
172+
.spyOn(exec, 'exec')
173+
.mockImplementation(
174+
async (program: string, args?: string[]): Promise<number> => 0
175+
)
188176

189177
const builder = new build.SnapcraftBuilder(
190178
'.',
@@ -203,8 +191,6 @@ test('SnapcraftBuilder.build can pass additional arguments', async () => {
203191
'--rm',
204192
'--tty',
205193
'--privileged',
206-
'--security-opt',
207-
'apparmor=:docker-snapcraft:unconfined',
208194
'--volume',
209195
`${process.cwd()}:/data`,
210196
'--workdir',

__tests__/tools.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ afterEach(() => {
88
jest.restoreAllMocks()
99
})
1010

11-
test('ensureDisabledAppArmorRules creates new AppArmor namespace', async () => {
12-
expect.assertions(1)
13-
14-
const execMock = jest.spyOn(exec, 'exec').mockImplementation(
15-
async (program: string, args?: string[]): Promise<number> => {
16-
return 0
17-
}
18-
)
19-
20-
await tools.ensureDisabledAppArmorRules()
21-
22-
expect(execMock).toHaveBeenNthCalledWith(1, 'sudo', [
23-
'mkdir',
24-
'/sys/kernel/security/apparmor/policy/namespaces/docker-snapcraft'
25-
])
26-
})
27-
2811
test('ensureDockerExperimental is no-op if experimental already set', async () => {
2912
expect.assertions(3)
3013

action.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: 'Snapcraft Build'
22
description: 'Build a Snapcraft project for multiple architectures'
3-
author: 'Daniel Llewellyn'
3+
author: 'Dani Llewellyn'
44
branding:
55
icon: 'package'
66
color: 'orange'
@@ -55,6 +55,5 @@ outputs:
5555
snap:
5656
description: 'The file name of the resulting snap.'
5757
runs:
58-
using: 'node12'
58+
using: 'node16'
5959
main: 'dist/index.js'
60-
post: 'dist/index.js'

dist/index.js

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports =
33
/******/ "use strict";
44
/******/ var __webpack_modules__ = ({
55

6-
/***/ 290:
6+
/***/ 761:
77
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
88

99
// ESM COMPAT FLAG
@@ -12,15 +12,15 @@ __webpack_require__.r(__webpack_exports__);
1212
// EXTERNAL MODULE: external "fs"
1313
var external_fs_ = __webpack_require__(747);
1414

15-
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
16-
var core = __webpack_require__(186);
17-
1815
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
1916
var exec = __webpack_require__(514);
2017

2118
// EXTERNAL MODULE: external "os"
2219
var external_os_ = __webpack_require__(87);
2320

21+
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
22+
var core = __webpack_require__(186);
23+
2424
// EXTERNAL MODULE: external "path"
2525
var external_path_ = __webpack_require__(622);
2626

@@ -57,14 +57,6 @@ function haveFile(filePath) {
5757
return true;
5858
});
5959
}
60-
function ensureDisabledAppArmorRules() {
61-
return __awaiter(this, void 0, void 0, function* () {
62-
yield exec.exec('sudo', [
63-
'mkdir',
64-
'/sys/kernel/security/apparmor/policy/namespaces/docker-snapcraft'
65-
]);
66-
});
67-
}
6860
function ensureDockerExperimental() {
6961
return __awaiter(this, void 0, void 0, function* () {
7062
let json = {};
@@ -238,10 +230,9 @@ class SnapcraftBuilder {
238230
}
239231
build() {
240232
return build_awaiter(this, void 0, void 0, function* () {
241-
yield ensureDisabledAppArmorRules();
242233
yield ensureDockerExperimental();
243234
const base = yield detectBase(this.projectRoot);
244-
if (!['core', 'core18', 'core20'].includes(base)) {
235+
if (!['core', 'core18', 'core20', 'core22'].includes(base)) {
245236
throw new Error(`Your build requires a base that this tool does not support (${base}). 'base' or 'build-base' in your 'snapcraft.yaml' must be one of 'core', 'core18' or 'core20'.`);
246237
}
247238
const imageInfo = {
@@ -270,8 +261,6 @@ class SnapcraftBuilder {
270261
'--rm',
271262
'--tty',
272263
'--privileged',
273-
'--security-opt',
274-
'apparmor=:docker-snapcraft:unconfined',
275264
'--volume',
276265
`${this.projectRoot}:/data`,
277266
'--workdir',
@@ -309,17 +298,6 @@ class SnapcraftBuilder {
309298
}
310299
}
311300

312-
// CONCATENATED MODULE: ./lib/state-helper.js
313-
314-
const isPost = !!process.env['STATE_isPost'];
315-
const tmpDir = process.env['STATE_tmpDir'] || '';
316-
function setTmpDir(dir) {
317-
core.saveState('tmpDir', dir);
318-
}
319-
if (!isPost) {
320-
core.saveState('isPost', 'true');
321-
}
322-
323301
// CONCATENATED MODULE: ./lib/main.js
324302
// -*- mode: javascript; js-indent-level: 2 -*-
325303
var main_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
@@ -334,8 +312,6 @@ var main_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arg
334312

335313

336314

337-
338-
339315
function run() {
340316
var _a;
341317
return main_awaiter(this, void 0, void 0, function* () {
@@ -362,20 +338,7 @@ function run() {
362338
}
363339
});
364340
}
365-
function cleanup() {
366-
return main_awaiter(this, void 0, void 0, function* () {
367-
yield exec.exec('sudo', [
368-
'rmdir',
369-
'/sys/kernel/security/apparmor/policy/namespaces/docker-snapcraft'
370-
]);
371-
});
372-
}
373-
if (!isPost) {
374-
run();
375-
}
376-
else {
377-
cleanup();
378-
}
341+
run();
379342

380343

381344
/***/ }),
@@ -6164,6 +6127,6 @@ module.exports = require("util");
61646127
/******/ // module exports must be returned from runtime so entry inlining is disabled
61656128
/******/ // startup
61666129
/******/ // Load entry module and return exports
6167-
/******/ return __webpack_require__(290);
6130+
/******/ return __webpack_require__(761);
61686131
/******/ })()
61696132
;

0 commit comments

Comments
 (0)