picostack / pico

A Git-driven task runner built to facilitate GitOps and Infrastructure-as-Code while securely passing secrets to tasks.
https://pico.sh
MIT License
54 stars 6 forks source link

env_file fails to find file on host machine when deployed #94

Open ADRFranklin opened 3 years ago

ADRFranklin commented 3 years ago

after testing a little bit with this, it seems when deploying with pico, docker compose is unable to find env files on the host system, which can be confirmed when you copy pico's params that are passed to docker compose and run them yourself.

Pico's Attempt:

{"level":"debug","ts":"2021-11-05T21:44:48.560Z","caller":"executor/cmd.go:101","msg":"executing with secrets","target":"pico-pterodactyl-panel","cmd":["docker-compose","up","-d"],"url":"https://gitlab.com/xxx/pico-pterodactyl-panel","dir":"/cache/pico-pterodactyl-panel","env":{"DATA_DIR":"/storage","DOMAIN_NAME":"xxx","HOSTNAME":"local-01","MACHINE_NAME":"local-01"},"passthrough":false}
Couldn't find env file: /storage/pterodactyl/conf.d/panel.env

Manual Attempt:

 DATA_DIR=/storage HOSTNAME="local-01" DOMAIN_NAME="xxx" docker-compose up -d
Creating network "pico-pterodactyl-panel_default" with the default driver
Pulling cache (redis:alpine)...
alpine: Pulling from library/redis
a0d0a0d46f8b: Already exists

as seen from above, running manually works perfectly fine.

Southclaws commented 2 years ago

Can you provide an MVCE for this? A simple Docker compose config and Pico target

ADRFranklin commented 2 years ago

Sure,

Config

E("DATA_DIR", "/storage");
E("MACHINE_NAME", HOSTNAME);

var GITLAB_HOST = "https://gitlab.com/";

A({
  name: "gitlab",
  path: "/pico",
  user_key: "GIT_USERNAME",
  pass_key: "GIT_PASSWORD",
});

function Compose(name) {
  return {
    name: name,
    url: GITLAB_HOST + "user/" + name,
    up: ["docker-compose", "up", "-d"],
    down: ["docker-compose", "down"],
    auth: "gitlab",
  };
}

if (HOSTNAME === "local-01") {
  E("DOMAIN_NAME", "domain");
  T(Compose("pico-pterodactyl-panel"));
}

pico-pterodactyl-panel docker compose

version: '2.3'
networks:
  default:
    driver: bridge
  gateway:
    external:
      name: gateway
services:
  ##
  # --Pterodactyl Panel--
  # This is the container that provides the main web interface.
  ##
  panel:
    depends_on:
      cache:
        condition: service_started
    env_file: ${DATA_DIR:?required}/pterodactyl/conf.d/panel.env
    image: ccarney16/pterodactyl-panel:latest
    restart: always
    networks:
      - default
      - gateway
    volumes:
      - ${DATA_DIR:?required}/pterodactyl/panel:/data
      # Enable Let's Encrypt Support
      - ${DATA_DIR:?required}/pterodactyl/conf.d/letsencrypt:/etc/letsencrypt
      - ${DATA_DIR:?required}/pterodactyl/conf.d/letsencrypt/webroot/.well-known:/var/www/html/public/.well-known
      - ${DATA_DIR:?required}/pterodactyl/conf.d/certs:/etc/certs
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=gateway"
      - "traefik.http.routers.pterodactyl-panel.rule=Host(`panel-${HOSTNAME:?required}.${DOMAIN_NAME:?required}`)"
      - "traefik.http.routers.pterodactyl-panel.entrypoints=https"
      - "traefik.http.routers.pterodactyl-panel.tls.certresolver=default"
      - "traefik.http.services.pterodactyl-panel.loadbalancer.server.port=80"
      - "com.centurylinklabs.watchtower.enable=true"
  ##
  # --Worker--
  # These are required for schedules and other misc tasks to 
  # function correctly.
  ##
  worker:
    command: wait-for -t 5 panel:80 -- php /var/www/html/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
    networks:
      - default
    depends_on:
      panel:
        condition: service_started
    env_file: ${DATA_DIR:?required}/pterodactyl/conf.d/panel.env
    image: ccarney16/pterodactyl-panel:latest
    labels:
      ofelia.enabled: "true"
      ofelia.job-exec.pqueue.schedule: "@every 1m"
      ofelia.job-exec.pqueue.command: "php /var/www/html/artisan schedule:run"
      ofelia.job-exec.pqueue.user: "nginx"
    restart: always
    volumes_from:
    - panel
  cron:
    command: daemon --docker
    depends_on:
      panel:
        condition: service_started
      worker:
        condition: service_started
    image: mcuadros/ofelia:latest
    network_mode: none
    privileged: true
    restart: always
    volumes:
    - ${DOCKER_SOCKET:-/var/run/docker.sock}:${DOCKER_SOCKET:-/var/run/docker.sock}
  ##
  # --Redis--
  # Handles Session Data
  ##
  cache:
    networks:
      - default
    cpu_count: 2
    cpu_percent: 50
    image: redis:alpine
    mem_limit: 128m
    restart: always
  ##
  # --MariaDB--
  # Required for the control panel to work.
  # Stores Server/User information
  ##
  game_mysql:
    image: mariadb:10.4
    networks:
      - default  
    env_file: ${DATA_DIR:?required}/pterodactyl/conf.d/mariadb.env
    ports:
    - ${MYSQL_ADDRESS:-3306}
    restart: always
    volumes:
    - ${DATA_DIR:?required}/pterodactyl/db:/var/lib/mysql    

link to env files needed https://github.com/ccarney16/pterodactyl-containers/tree/master/manifest/config/env