Skip to content

Commit

Permalink
fix(command): fixing docker command
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasim committed Nov 3, 2024
1 parent 5792d83 commit 458195e
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 32 deletions.
8 changes: 7 additions & 1 deletion src/parsers/aws-cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class CloudFormationParser extends BaseParser {
}
};

const commandArray = typeof serviceConfig.command === 'string'
? serviceConfig.command.split(' ')

Check failure on line 83 in src/parsers/aws-cloudformation.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected indentation of 8 spaces but found 6
: Array.isArray(serviceConfig.command)

Check failure on line 84 in src/parsers/aws-cloudformation.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected indentation of 8 spaces but found 6
? serviceConfig.command

Check failure on line 85 in src/parsers/aws-cloudformation.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected indentation of 10 spaces but found 8
: [];

Check failure on line 86 in src/parsers/aws-cloudformation.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected indentation of 10 spaces but found 8

const ports = new Set<number>();
serviceConfig.ports?.map((value) => {
ports.add(Number(value.split(':')[0]));
Expand Down Expand Up @@ -112,7 +118,7 @@ class CloudFormationParser extends BaseParser {
ContainerDefinitions: [
{
Name: serviceName,
Command: serviceConfig.command?.split(' '),
Command: commandArray,
Image: `docker.io/${serviceConfig.image}`,
PortMappings: [ ...Array.from(ports.values()).map((value) => {
return { ContainerPort: value };
Expand Down
14 changes: 9 additions & 5 deletions src/parsers/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ const defaultParserConfig: DefaultParserConfig = {
templateFormat: TemplateFormat.yaml
};

// Assuming you need to convert Docker Compose service to Render service details.

class RenderParser extends BaseParser {

parse(dockerCompose: DockerCompose, templateFormat: TemplateFormat = defaultParserConfig.templateFormat): any {
const services: Array<any> = [];



for (const [serviceName, serviceConfig] of Object.entries(dockerCompose.services)) {

const ports = new Set<number>();
Expand All @@ -35,15 +34,20 @@ class RenderParser extends BaseParser {

if (ports.size > 0) {
environmentVariables['PORT'] = Array.from(ports)[0]; // Binding port
}
}

// Handle different possible types for command
const startCommand = Array.isArray(serviceConfig.command)
? serviceConfig.command.join(' ')
: serviceConfig.command || '';

const service: any = {
name: serviceName,
type: 'web',
env: 'docker',
runtime: 'image',
image: { url: `docker.io/library/${serviceConfig.image}` },
startCommand: serviceConfig.command || '',
startCommand,
plan: defaultParserConfig.subscriptionName, // Change according to your needs, Render offers "free", "starter', "standard', "pro"
region: defaultParserConfig.region, // Default example region, adjust based on preference
envVars: Object.entries(environmentVariables).map(([key, value]) => ({
Expand Down
36 changes: 36 additions & 0 deletions test/sample-docker-compose-simple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.2'

services:
db:
image: redis:latest
restart: always
volumes:
- rediscache:/data
environment:
- MYSQL_ROOT_PASSWORD=
- MARIADB_AUTO_UPGRADE=1
- MARIADB_DISABLE_UPGRADE_BACKUP=1
ports:
- '6379:6379'

web:
image: nginx:alpine
restart: always
environment:
MARIADB_ROOT_PASSWORD: "ganzgeheim"
MARIADB_PASSWORD: "geheim"
MARIADB_USER: "testuser"
MARIADB_DATABASE: "testdb"
command: >
/bin/bash -c "whoami
&& ls / ls -al /var/"
volumes:
- volumenginx:/var/www/html:z,ro
ports:
- 8080:80
- "8081:80" # just for testing duplicate port setup
- 8080:443

volumes:
rediscache:
volumenginx:
240 changes: 214 additions & 26 deletions test/sample-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,224 @@
version: '3.2'
---
# Example file from: https://github.com/FerretDB/FerretDB/blob/main/docker-compose.yml

services:
db:
image: redis:latest
restart: always
postgres:
build:
context: ./build/deps
dockerfile: ${POSTGRES_DOCKERFILE:-postgres}.Dockerfile
container_name: ferretdb_postgres
command: >
postgres
-c log_min_duration_statement=1000ms
-c log_min_error_statement=WARNING
-c log_min_messages=WARNING
-c max_connections=400
ports:
- 5432:5432
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
# UTC−03:30/−02:30. Set to catch timezone problems.
- TZ=America/St_Johns
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=ferretdb

postgres_secured:
build:
context: ./build/deps
dockerfile: postgres.Dockerfile
container_name: ferretdb_postgres_secured
command: >
postgres
-c log_min_duration_statement=1000ms
-c log_min_error_statement=WARNING
-c log_min_messages=WARNING
-c max_connections=400
ports:
- 5433:5432
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
# UTC−03:30/−02:30. Set to catch timezone problems.
- TZ=America/St_Johns
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=ferretdb

mysql:
build:
context: ./build/deps
dockerfile: mysql.Dockerfile
container_name: ferretdb_mysql
command:
- --slow_query_log=1
- --long_query_time=1
- --log_error_verbosity=2
- --max_connections=200
ports:
- 3306:3306
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
# UTC−03:30/−02:30. Set to catch timezone problems.
- TZ=America/St_Johns
- MYSQL_ROOT_PASSWORD=password
- MYSQL_USER=username
- MYSQL_PASSWORD=password
- MYSQL_DATABASE=ferretdb

mongodb:
build:
context: ./build/deps
dockerfile: mongo.Dockerfile
container_name: ferretdb_mongodb
command: --config /etc/mongodb.conf
ports:
- 47017:47017
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
# Always UTC+05:45. Set to catch timezone problems.
- TZ=Asia/Kathmandu
volumes:
- rediscache:/data
- ./build/certs:/etc/certs
- ./build/mongodb.conf:/etc/mongodb.conf

mongodb_secured:
build:
context: ./build/deps
dockerfile: mongo.Dockerfile
container_name: ferretdb_mongodb_secured
command: --config /etc/mongodb.conf
ports:
- 47018:47018
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
# Always UTC+05:45. Set to catch timezone problems.
- TZ=Asia/Kathmandu
- MONGO_INITDB_ROOT_USERNAME=username
- MONGO_INITDB_ROOT_PASSWORD=password
volumes:
- ./build/certs:/etc/certs
- ./build/mongodb_secured.conf:/etc/mongodb.conf

# for test scripts
legacy-mongo-shell:
build:
context: ./build/deps
dockerfile: legacy-mongo-shell.Dockerfile
container_name: ferretdb_legacy-mongo-shell
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- MYSQL_ROOT_PASSWORD=
- MARIADB_AUTO_UPGRADE=1
- MARIADB_DISABLE_UPGRADE_BACKUP=1
# Always UTC+05:45. Set to catch timezone problems.
- TZ=Asia/Kathmandu
volumes:
- ./build/certs:/etc/certs
- ./build/legacy-mongo-shell/test.js:/legacy-mongo-shell/test.js

jaeger:
build:
context: ./build/deps
dockerfile: jaeger.Dockerfile
container_name: ferretdb_jaeger
environment:
- COLLECTOR_OTLP_ENABLED=true
ports:
- '6379:6379'
- 4318:4318 # OTLP over HTTP
- 6831:6831/udp # Compact Thrift from BuildKit
- 16686:16686 # UI on http://127.0.0.1:16686/

trivy:
build:
context: ./build/deps
dockerfile: trivy.Dockerfile
container_name: ferretdb_trivy
volumes:
- .:/workdir

web:
image: nginx:alpine
restart: always
# for YAML files
prettier:
build:
context: ./build/deps
dockerfile: ferretdb-prettier.Dockerfile
container_name: ferretdb_ferretdb-prettier
volumes:
- .:/workdir

# for documentation
textlint:
build:
context: ./build/deps
dockerfile: ferretdb-textlint.Dockerfile
container_name: ferretdb_ferretdb-textlint
volumes:
- .:/workdir
markdownlint:
build:
context: ./build/deps
dockerfile: markdownlint.Dockerfile
container_name: ferretdb_markdownlint
volumes:
- .:/workdir
wrangler:
build:
context: ./build/deps
dockerfile: ferretdb-wrangler.Dockerfile
container_name: ferretdb_ferretdb-wrangler
ports:
- 8976:8976 # simplifies authentication for testing
environment:
MARIADB_ROOT_PASSWORD: "ganzgeheim"
MARIADB_PASSWORD: "geheim"
MARIADB_USER: "testuser"
MARIADB_DATABASE: "testdb"
command: >
/bin/bash -c "whoami
&& ls / ls -al /var/"
- CLOUDFLARE_ACCOUNT_ID
- CLOUDFLARE_API_TOKEN
- WRANGLER_SEND_METRICS=false
# - WRANGLER_LOG=debug # TODO https://github.com/cloudflare/workers-sdk/issues/3073
volumes:
- .:/workdir # mount everything for wrangler to pick up branch name, commit hash, etc from git
docusaurus-docs:
build:
context: ./build/deps
dockerfile: docusaurus-docs.Dockerfile
container_name: ferretdb_docusaurus-docs
ports:
- 3000:3000
volumes:
- volumenginx:/var/www/html:z,ro
# shared with blog
- ./website/babel.config.js:/workdir/docusaurus-docs/babel.config.js:ro
- ./website/sidebars.js:/workdir/docusaurus-docs/sidebars.js:ro
- ./website/src:/workdir/docusaurus-docs/src:ro
- ./website/static:/workdir/docusaurus-docs/static:ro
- ./website/build:/workdir/docusaurus-docs/build:rw

# docs sources
- ./website/docs:/workdir/docusaurus-docs/docs:rw
- ./website/docusaurus.config.js:/workdir/docusaurus-docs/docusaurus.config.js:ro
- ./website/versioned_docs:/workdir/docusaurus-docs/versioned_docs:rw
- ./website/versioned_sidebars:/workdir/docusaurus-docs/versioned_sidebars:rw
- ./website/versions.json:/workdir/docusaurus-docs/versions.json:rw

docusaurus-blog:
build:
context: ./build/deps
dockerfile: docusaurus-docs.Dockerfile
container_name: ferretdb_docusaurus-blog
ports:
- 8080:80
- "8081:80" # just for testing duplicate port setup
- 8080:443
- 3001:3001
volumes:
# shared with docs
- ./website/babel.config.js:/workdir/docusaurus-docs/babel.config.js:ro
- ./website/sidebars.js:/workdir/docusaurus-docs/sidebars.js:ro
- ./website/src:/workdir/docusaurus-docs/src:ro
- ./website/static:/workdir/docusaurus-docs/static:ro
- ./website/build:/workdir/docusaurus-docs/build:rw

# blog sources
- ./website/blog:/workdir/docusaurus-docs/blog:ro
- ./website/docusaurus.config-blog.js:/workdir/docusaurus-docs/docusaurus.config.js:ro

volumes:
rediscache:
volumenginx:
networks:
default:
name: ferretdb

0 comments on commit 458195e

Please sign in to comment.