Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Daemon running check #1140

Merged
merged 6 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"lib_helpers_manifest_unableToDump": "Unable to dump manifest: {manifest}",
"lib_helpers_manifest_unableToLoad": "Unable to load manifest: {path}",
"lib_helpers_docker_copyText": "Artifacts written to {path} from the image `{image}`",
"lib_helpers_docker_couldNotConnect": "Could not connect to the Docker daemon. Is the docker daemon running?",
"lib_helpers_docker_copyError": "Failed to write build artifacts to {path} from the image `{image}`",
"lib_helpers_docker_copyWarning": "Warnings write build artifacts to {path} from the image `{image}`",
"lib_helpers_docker_buildText": "Building source image `{image}` using dockerfile `{dockerfile}` in context `{context}`",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"lib_helpers_manifest_outputWarning": "Warnings writing manifest to {path}",
"lib_helpers_manifest_unableToDump": "Unable to dump manifest: {manifest}",
"lib_helpers_manifest_unableToLoad": "Unable to load manifest: {path}",
"lib_helpers_docker_couldNotConnect": "Could not connect to the Docker daemon. Is the docker daemon running?",
"lib_helpers_docker_copyText": "Artifacts written to {path} from the image `{image}`",
"lib_helpers_docker_copyError": "Failed to write build artifacts to {path} from the image `{image}`",
"lib_helpers_docker_copyWarning": "Warnings write build artifacts to {path} from the image `{image}`",
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/lib/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
copyArtifactsFromBuildImage,
createBuildImage,
displayPath,
ensureDockerDaemonRunning,
generateDockerfile,
generateDockerImageName,
intlMsg,
Expand Down Expand Up @@ -248,6 +249,7 @@ export class Compiler {

private async _buildSourcesInDocker(): Promise<string> {
const { project, outputDir } = this._config;
await ensureDockerDaemonRunning();
const buildManifestDir = await project.getBuildManifestDir();
const buildManifest = await project.getBuildManifest();
const imageName =
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/lib/infra/Infra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
intlMsg,
dependencyFetcherClassMap,
correctBuildContextPathsFromCompose,
ensureDockerDaemonRunning,
DockerCompose,
CacheDirectory,
} from "../";
Expand Down Expand Up @@ -76,6 +77,8 @@ export class Infra {
}

public async up(): Promise<void> {
await ensureDockerDaemonRunning();

const modulesWithPaths = await this._fetchModules();

await this._dockerCompose.commands.upAll({
Expand All @@ -86,6 +89,8 @@ export class Infra {
}

public async down(): Promise<void> {
await ensureDockerDaemonRunning();

const modulesWithPaths = await this._fetchModules();

await this._dockerCompose.commands.down({
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/lib/system/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ export function isDockerInstalled(): boolean {
return !!system.which("docker");
}

export async function ensureDockerDaemonRunning(): Promise<void> {
try {
await system.run("docker stats --no-stream");
} catch (e) {
throw new Error(intlMsg.lib_helpers_docker_couldNotConnect());
}
}

export function getDockerFileLock(): FileLock {
return new FileLock(__dirname + "/DOCKER_LOCK", print.error);
}
Expand Down