version: "3.7"
########################### NETWORKS
# There is no need to create any networks outside this docker-compose file.
# You may customize the network subnets (192.168.90.0/24 and 91.0/24) below as you please.
# Docker Compose version 3.5 or higher required to define networks this way.
networks:
  gl_proxy:
    name: gl_proxy
    driver: bridge
    ipam:
      config:
        - subnet: $GL_PROXY_SUBNET
        - gateway: $GL_PROXY_GATEWAY 
  default:
    driver: bridge
  gl_socket_proxy:
    name: gl_socket_proxy
    driver: bridge
    ipam:
      config:
        - subnet: $GL_SOCKET_PROXY_SUBNET
        - gateway: $GL_SOCKET_PROXY_GATEWAY

########################### SERVICES
services:
  # VSCode - VSCode Editing
  # sudo chown -R 1000:1000 /home/coder/project
  vscode:
    image: codercom/code-server:latest
#    image: linuxserver/code-server
#    image: linuxserver/openvscode-server
    container_name: gl-vscode
    restart: always    
    networks:
      gl_proxy:
        ipv4_address: $VSCODE_IP
    # ports:
#        "$VSCODE_PORT:8443"
    volumes:      
#       - $DOCKERDIR/appdata/vscode:/config
      - $USERDIR/server:/home/coder/server      
      - $DOCKERDIR:/home/coder/docker      
      - $DOCKERDIR/appdata/vscode:/home/coder      
      #- /media/hdd1:/home/coder/hdd1    
    environment:    
      TZ: $TZ
#      - SUDO_PASSWORD=password # If this optional variable is set, user will have sudo access in the code-server terminal with the specified password.
#      PUID: $PUID
#     PROXY_DOMAIN=code-server.my.domain # If this optional variable is set, this domain will be proxied for subdomain proxying.
#      PGID: $PGID # for GroupID
      PASSWORD: $VSCODE_PASSWORD
      # Run as root first, create the directories, then change permissions to user:docker and 775. Disable run as root below.    
      user: $PUID:$PGID    
#      user: "0"    
      DOCKER_HOST: $DOCKER_ENDPOINT 
    labels:    
        - "traefik.enable=true"    
        ## HTTP Routers    
        - "traefik.http.routers.vscode-rtr.entrypoints=https"    
        - "traefik.http.routers.vscode-rtr.rule=Host(`code.local.$DOMAINNAME0`)"    
        ## Middlewares    
        - "traefik.http.routers.vscode-rtr.middlewares=chain-authelia@file" 
        ## HTTP Services    
        - "traefik.http.routers.vscode-rtr.service=vscode-svc"    
        - "traefik.http.services.vscode-svc.loadbalancer.server.port=8080"
#        - "traefik.http.services.vscode-svc.loadbalancer.server.port=8443"
