redhat-developer / henge

This project has merged into Kompose.
https://github.com/skippbox/kompose
MIT License
14 stars 7 forks source link

support for variable lookup from environment and .env file #18

Closed surajssd closed 8 years ago

surajssd commented 8 years ago

Now environment variables in docker compose file can be substituted from the operating system environment or .env file.

This has been merged in upstream https://github.com/openshift/origin/pull/9316

fixes issue #13

kadel commented 8 years ago

If this is already fixed in origin, all that is needed is to update vendored dependency using godeps. I'm going to document steps how to do this, as it can be little bit tricky :-(

rtnpro commented 8 years ago

On Wed, Jun 22, 2016 at 2:21 PM, Tomas Kral notifications@github.com wrote:

If this is already fixed in origin, all that is needed is to update vendored dependency using godeps. I'm going to document steps how to do this, as it can be little bit tricky :-(

It's tricky indeed, because of the k8s hack :)

kadel commented 8 years ago

There is even more problems https://github.com/openshift/origin/issues/9416#issuecomment-227252211

surajssd commented 8 years ago

After rebasing with the latest changes

Docker compose file:

$ cat docker-compose.yml 
version: "2"

services:
  postgresql:
    image: swordphilic/postgresql
    ports:
      - "$DB_PORT"
    environment:
      DB_NAME: $DB_NAME
      DB_PASS: $DB_PASS
      DB_USER: $DB_USER

  gitlab:
    image: swordphilic/gitlab
    ports:
      - "30000:80"
      - "30001:443"
      - "30002:22"
    restart: always
    environment:
      DB_TYPE: postgres
      DB_HOST: postgresql
      DB_NAME: $DB_NAME
      DB_PASS: $DB_PASS
      DB_USER: $DB_USER
      REDIS_HOST: redis

  redis:
    image: swordphilic/redis
    ports:
      - "$REDIS_PORT"

env vars

$ cat envs 
DB_PORT=5432
DB_NAME=gitlab
DB_PASS=gitlab
DB_USER=gitlab
REDIS_PORT=6379

running henge

$ export $(cat envs)
$ ./henge openshift 

output:

apiVersion: v1
items:
- apiVersion: v1
  kind: ImageStream
  metadata:
    creationTimestamp: null
    name: gitlab
  spec:
    tags:
    - annotations:
        openshift.io/imported-from: swordphilic/gitlab
      from:
        kind: DockerImage
        name: swordphilic/gitlab
      generation: null
      importPolicy: {}
      name: latest
  status:
    dockerImageRepository: ""
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    creationTimestamp: null
    name: gitlab
  spec:
    replicas: 1
    selector:
      deploymentconfig: gitlab
    strategy:
      resources: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          deploymentconfig: gitlab
      spec:
        containers:
        - env:
          - name: DB_HOST
            value: postgresql
          - name: DB_NAME
            value: gitlab
          - name: DB_PASS
            value: gitlab
          - name: DB_TYPE
            value: postgres
          - name: DB_USER
            value: gitlab
          - name: REDIS_HOST
            value: redis
          image: swordphilic/gitlab
          name: gitlab
          ports:
          - containerPort: 80
          - containerPort: 443
          - containerPort: 22
          resources: {}
    test: false
    triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
        - gitlab
        from:
          kind: ImageStreamTag
          name: gitlab:latest
      type: ImageChange
  status: {}
- apiVersion: v1
  kind: ImageStream
  metadata:
    creationTimestamp: null
    name: postgresql
  spec:
    tags:
    - annotations:
        openshift.io/imported-from: swordphilic/postgresql
      from:
        kind: DockerImage
        name: swordphilic/postgresql
      generation: null
      importPolicy: {}
      name: latest
  status:
    dockerImageRepository: ""
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    creationTimestamp: null
    name: postgresql
  spec:
    replicas: 1
    selector:
      deploymentconfig: postgresql
    strategy:
      resources: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          deploymentconfig: postgresql
      spec:
        containers:
        - env:
          - name: DB_NAME
            value: gitlab
          - name: DB_PASS
            value: gitlab
          - name: DB_USER
            value: gitlab
          image: swordphilic/postgresql
          name: postgresql
          ports:
          - containerPort: 5432
          resources: {}
    test: false
    triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
        - postgresql
        from:
          kind: ImageStreamTag
          name: postgresql:latest
      type: ImageChange
  status: {}
- apiVersion: v1
  kind: ImageStream
  metadata:
    creationTimestamp: null
    name: redis
  spec:
    tags:
    - annotations:
        openshift.io/imported-from: swordphilic/redis
      from:
        kind: DockerImage
        name: swordphilic/redis
      generation: null
      importPolicy: {}
      name: latest
  status:
    dockerImageRepository: ""
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    creationTimestamp: null
    name: redis
  spec:
    replicas: 1
    selector:
      deploymentconfig: redis
    strategy:
      resources: {}
    template:
      metadata:
        creationTimestamp: null
        labels:
          deploymentconfig: redis
      spec:
        containers:
        - image: swordphilic/redis
          name: redis
          ports:
          - containerPort: 6379
          resources: {}
    test: false
    triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
        - redis
        from:
          kind: ImageStreamTag
          name: redis:latest
      type: ImageChange
  status: {}
- apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: null
    name: gitlab
  spec:
    ports:
    - name: 22-tcp
      port: 22
      targetPort: 22
    - name: 80-tcp
      port: 80
      targetPort: 80
    - name: 443-tcp
      port: 443
      targetPort: 443
    selector:
      deploymentconfig: gitlab
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: null
    name: postgresql
  spec:
    ports:
    - name: 5432-tcp
      port: 5432
      targetPort: 5432
    selector:
      deploymentconfig: postgresql
  status:
    loadBalancer: {}
- apiVersion: v1
  kind: Service
  metadata:
    creationTimestamp: null
    name: redis
  spec:
    ports:
    - name: 6379-tcp
      port: 6379
      targetPort: 6379
    selector:
      deploymentconfig: redis
  status:
    loadBalancer: {}
kind: List
metadata: {}

surajssd commented 8 years ago

ping: @kadel

kadel commented 8 years ago

LGTM

surajssd commented 8 years ago

Rebased and merging!