Fixing docker-compose up linking to wrong directory when started in container
This commit is contained in:
parent
492fd2ed4e
commit
a864498d16
@ -97,5 +97,5 @@ the local tests).
|
|||||||
```console
|
```console
|
||||||
$ LIVE_RELOAD=0 docker-compose up -d
|
$ LIVE_RELOAD=0 docker-compose up -d
|
||||||
# Wait 2-3 minutes for the environment to start, then:
|
# Wait 2-3 minutes for the environment to start, then:
|
||||||
$ docker-compose -f docker-compose.testcafe.yaml up
|
$ PROJECT_DIR=$(pwd) docker-compose -f docker-compose.testcafe.yml up
|
||||||
```
|
```
|
||||||
|
@ -7,13 +7,10 @@ services:
|
|||||||
user: root
|
user: root
|
||||||
environment:
|
environment:
|
||||||
BROWSER: "chromium --use-fake-device-for-media-stream"
|
BROWSER: "chromium --use-fake-device-for-media-stream"
|
||||||
|
PROJECT_DIR: ${PROJECT_DIR}
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/project
|
- ./:/project
|
||||||
- ./maps:/maps
|
- ./maps:/maps
|
||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
# security_opt:
|
# security_opt:
|
||||||
# - seccomp:unconfined
|
# - seccomp:unconfined
|
||||||
|
|
||||||
networks:
|
|
||||||
default:
|
|
||||||
name: workadventure_dev
|
|
||||||
|
@ -239,7 +239,3 @@ services:
|
|||||||
# #- --cert=/root/letsencrypt/fullchain.pem
|
# #- --cert=/root/letsencrypt/fullchain.pem
|
||||||
# #- --pkey=/root/letsencrypt/privkey.pem
|
# #- --pkey=/root/letsencrypt/privkey.pem
|
||||||
# network_mode: host
|
# network_mode: host
|
||||||
|
|
||||||
networks:
|
|
||||||
default:
|
|
||||||
name: workadventure_dev
|
|
||||||
|
@ -4,6 +4,30 @@ import Dockerode = require( 'dockerode')
|
|||||||
const util = require('util');
|
const util = require('util');
|
||||||
const exec = util.promisify(require('child_process').exec);
|
const exec = util.promisify(require('child_process').exec);
|
||||||
const { execSync } = require('child_process');
|
const { execSync } = require('child_process');
|
||||||
|
const path = require("path");
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute Docker compose, passing the correct host directory (in case this is run from the TestCafe container)
|
||||||
|
*/
|
||||||
|
export function dockerCompose(command: string): void {
|
||||||
|
let param = '';
|
||||||
|
const projectDir = process.env.PROJECT_DIR;
|
||||||
|
|
||||||
|
if (!projectDir && fs.existsSync('/project')) {
|
||||||
|
// We are probably in the docker-image AND we did not pass PROJECT_DIR env variable
|
||||||
|
throw new Error('Incorrect docker-compose command used to fire testcafe tests. You need to add a PROJECT_DIR environment variable. Please refer to the CONTRIBUTING.md guide');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectDir) {
|
||||||
|
const dirName = path.basename(projectDir);
|
||||||
|
param = '--project-name '+dirName+' --project-directory '+projectDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
let stdout = execSync('docker-compose '+param+' '+command, {
|
||||||
|
cwd: __dirname + '/../../../'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a container ID based on the container name.
|
* Returns a container ID based on the container name.
|
||||||
@ -35,81 +59,27 @@ export async function startContainer(container: Dockerode.ContainerInfo): Promis
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function rebootBack(): Promise<void> {
|
export async function rebootBack(): Promise<void> {
|
||||||
let stdout = execSync('docker-compose up --force-recreate -d back', {
|
dockerCompose('up --force-recreate -d back');
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
/*const container = await findContainer('back');
|
|
||||||
await stopContainer(container);
|
|
||||||
await startContainer(container);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function rebootTraefik(): void {
|
export function rebootTraefik(): void {
|
||||||
let stdout = execSync('docker-compose up --force-recreate -d reverse-proxy', {
|
dockerCompose('up --force-recreate -d reverse-proxy');
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
|
|
||||||
//console.log('rebootTraefik', stdout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function rebootPusher(): Promise<void> {
|
export async function rebootPusher(): Promise<void> {
|
||||||
let stdout = execSync('docker-compose up --force-recreate -d pusher', {
|
dockerCompose('up --force-recreate -d pusher');
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
/*const container = await findContainer('pusher');
|
|
||||||
await stopContainer(container);
|
|
||||||
await startContainer(container);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resetRedis(): Promise<void> {
|
export async function resetRedis(): Promise<void> {
|
||||||
let stdout = execSync('docker-compose stop redis', {
|
dockerCompose('stop redis');
|
||||||
cwd: __dirname + '/../../../'
|
dockerCompose('rm -f redis');
|
||||||
});
|
dockerCompose('up --force-recreate -d redis');
|
||||||
//console.log('rebootRedis', stdout);
|
|
||||||
|
|
||||||
stdout = execSync('docker-compose rm -f redis', {
|
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
//console.log('rebootRedis', stdout);
|
|
||||||
|
|
||||||
stdout = execSync('docker-compose up --force-recreate -d redis', {
|
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
|
|
||||||
//console.log('rebootRedis', stdout);
|
|
||||||
/*
|
|
||||||
let stdout = execSync('docker-compose stop redis', {
|
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
console.log('stdout:', stdout);
|
|
||||||
stdout = execSync('docker-compose rm redis', {
|
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
//const { stdout, stderr } = await exec('docker-compose down redis');
|
|
||||||
console.log('stdout:', stdout);
|
|
||||||
//console.log('stderr:', stderr);
|
|
||||||
const { stdout2, stderr2 } = await exec('docker-compose up -d redis');
|
|
||||||
console.log('stdout:', stdout2);
|
|
||||||
console.log('stderr:', stderr2);
|
|
||||||
*/
|
|
||||||
/*const container = await findContainer('redis');
|
|
||||||
//await stopContainer(container);
|
|
||||||
//await startContainer(container);
|
|
||||||
|
|
||||||
const docker = new Dockerode();
|
|
||||||
await docker.getContainer(container.Id).stop();
|
|
||||||
await docker.getContainer(container.Id).remove();
|
|
||||||
const newContainer = await docker.createContainer(container);
|
|
||||||
await newContainer.start();*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopRedis(): void {
|
export function stopRedis(): void {
|
||||||
let stdout = execSync('docker-compose stop redis', {
|
dockerCompose('stop redis');
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function startRedis(): void {
|
export function startRedis(): void {
|
||||||
let stdout = execSync('docker-compose start redis', {
|
dockerCompose('start redis');
|
||||||
cwd: __dirname + '/../../../'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user