Skip to content

Commit

Permalink
codespaces: setup custom network for docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
ivandotv authored May 30, 2022
1 parent e2b7841 commit c29f35b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 27017],
"forwardPorts": [3000, 27017, 9000],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "npm i -g pnpm@6 && pnpm install",
Expand Down
5 changes: 4 additions & 1 deletion .devcontainer/docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
version: '3'
services:
db:
image: mongo:latest
image: mongo:5.0.8
ports:
- 27017:27017
volumes:
- mongodb-data:/data/db
networks:
- default
- development
# Uncomment to change startup options
# environment:
# MONGO_INITDB_ROOT_USERNAME: root
Expand Down
11 changes: 8 additions & 3 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ services:
dockerfile: Dockerfile
args:
INSTALL_ZSH: 'false'

networks:
- default
- development
volumes:
# Forwards the local Docker socket to the container.
- /var/run/docker.sock:/var/run/docker-host.sock
Expand All @@ -28,5 +30,8 @@ services:

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
volumes:
mongodb-data: null
networks:
default:
development:
external: false
name: development
2 changes: 0 additions & 2 deletions .env

This file was deleted.

10 changes: 2 additions & 8 deletions src/__tests__/database/jestGlobalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ let firstRun = true
export default async function jestGlobalSetup(_config: any) {
process.env.JEST_FIRST_RUN = firstRun ? 'yes' : 'no'

// process.env.MONGO_DB_URI = 'not_used'
// process.env.MONGO_DB_NAME = 'not_used'

if (firstRun) {
console.log('\nsetup started')
const end = timeSpan()
Expand All @@ -37,7 +34,7 @@ async function initializeMongo() {
Boolean(process.env.REMOTE_CONTAINERS) || Boolean(process.env.CODESPACES)
const newtworkAlias = 'mongo-test-db'

const mongoContainer = new GenericContainer('mongo:5.0.7').withExposedPorts(
const mongoContainer = new GenericContainer('mongo:5.0.8').withExposedPorts(
27017
)

Expand All @@ -47,23 +44,20 @@ async function initializeMongo() {
}
if (remoteContainers) {
mongoContainer
.withNetworkMode('live-radio_default')
.withNetworkMode('development')
.withNetworkAliases(newtworkAlias)
}

const mongoStarted = await startContainer(mongoContainer, 'mongo')

const host = remoteContainers ? newtworkAlias : 'localhost'

console.log('REMOTE CONTAINERS', remoteContainers)
const port = remoteContainers
? '27017'
: (mongoStarted.getMappedPort(27017) as unknown as string)

process.env.MONGO_DB_URI = `mongodb://${host}:${port}`

console.log('jest global setup')

return mongoStarted
}

Expand Down

0 comments on commit c29f35b

Please sign in to comment.