Skip to content

Commit

Permalink
fix(cli): fix missing dockerfile error (#2988)
Browse files Browse the repository at this point in the history
* Warn users of not found process types

* Warn if process type doesn't exist

* Add test for missing dockerfile
  • Loading branch information
eablack committed Aug 23, 2024
1 parent d46786a commit 1f880e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/cli/src/lib/container/docker_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as glob from 'glob'
import * as Path from 'path'
import * as inquirer from 'inquirer'
import * as os from 'os'
import {ux} from '@oclif/core'

const DOCKERFILE_REGEX = /\bDockerfile(.\w*)?$/

Expand Down Expand Up @@ -140,6 +141,11 @@ export const chooseJobs = async function (jobs: groupedDockerJobs) {
for (const processType in jobs) {
if (Object.prototype.hasOwnProperty.call(jobs, processType)) {
const group = jobs[processType]
if (group === undefined) {
ux.warn(`Dockerfile.${processType} not found`)
continue
}

if (group.length > 1) {
const prompt = [{
type: 'list',
Expand Down
28 changes: 27 additions & 1 deletion packages/cli/test/unit/commands/container/push.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {stdout} from 'stdout-stderr'
import {stdout, stderr} from 'stdout-stderr'
import Cmd from '../../../../src/commands/container/push'
import runCommand from '../../../helpers/runCommand'
import {expect} from 'chai'
Expand Down Expand Up @@ -198,6 +198,32 @@ describe('container push', function () {
sandbox.assert.calledTwice(push)
})

it('warns when a specified Dockerfile is missing', async function () {
const dockerfiles = sandbox.stub(DockerHelper, 'getDockerfiles')
.returns(['/path/to/Dockerfile.web'])
const build = sandbox.stub(DockerHelper, 'buildImage')
build.withArgs('/path/to/Dockerfile.web', 'registry.heroku.com/testapp/web', [])
build.withArgs('/path/to/Dockerfile.worker', 'registry.heroku.com/testapp/worker', [])
const push = sandbox.stub(DockerHelper, 'pushImage')
push.withArgs('registry.heroku.com/testapp/web')
push.withArgs('registry.heroku.com/testapp/worker')

await runCommand(Cmd, [
'--app',
'testapp',
'--recursive',
'web',
'worker',
])

expect(stdout.output).to.contain('Building web (/path/to/Dockerfile.web)')
expect(stdout.output).to.contain('Pushing web (/path/to/Dockerfile.web)')
expect(stderr.output).to.contain('Dockerfile.worker not found')
sandbox.assert.calledOnce(dockerfiles)
sandbox.assert.calledOnce(build)
sandbox.assert.calledOnce(push)
})

it('pushes all dockerfiles recursively when process types are not specified', async function () {
const dockerfiles = sandbox.stub(DockerHelper, 'getDockerfiles')
.returns(['/path/to/Dockerfile.web', '/path/to/Dockerfile.worker'])
Expand Down

0 comments on commit 1f880e8

Please sign in to comment.