captainVersion: 4
services:
    $$cap_appname:
        caproverExtra:
            notExposeAsWebApp: 'true'
            dockerfileLines:
                - FROM alpine:3.15.0
                - RUN apk update && apk add openssh rsync nano openssl bash
                - ADD https://gist.githubusercontent.com/githubsaturn/b092f0f784263ebf2696c5613e9144e5/raw/0bd25d5bf7970e518bcfcfd58ca156e74b343afe/rsync-looper.sh /
                - RUN chmod +x /rsync-looper.sh
                - CMD /rsync-looper.sh
        environment:
            REMOTE_SOURCE_DIRECTORY: $$cap_REMOTE_SOURCE_DIRECTORY
            PRIVATE_KEY_BASE_64: $$cap_PRIVATE_KEY_BASE_64
            REMOTE_SSH_PORT: $$cap_REMOTE_SSH_PORT
            REMOTE_SSH_ADDRESS: $$cap_REMOTE_SSH_ADDRESS
            REMOTE_SSH_USER: $$cap_REMOTE_SSH_USER
            RSYNC_SLEEP_GAP: 30s
        volumes:
            - $$cap_appname-target-directory:/target-dir
caproverOneClickApp:
    variables:
        - id: $$cap_REMOTE_SOURCE_DIRECTORY
          label: Remote source location
          description: The remote directory from which the content will be downloaded
          defaultValue: '/backup-files/'

        - id: $$cap_PRIVATE_KEY_BASE_64
          label: The base64 encoded version of private key for establish the SSH connection.
          description: To convert your private to base64, run `cat private.key | openssl base64 | tr -d '\n'`
          validRegex: /.{20,}/

        - id: $$cap_REMOTE_SSH_PORT
          label: The remote SSH port.
          defaultValue: '22'

        - id: $$cap_REMOTE_SSH_ADDRESS
          label: The remote SSH address.
          description: Either an IP or a host such as captain.domain.com - DO NOT add HTTP(S)
          validRegex: /.{3,}/

        - id: $$cap_REMOTE_SSH_USER
          label: The remote SSH User
          description: Usually root, unless you set up another user
          validRegex: /.{1,}/
    instructions:
        start: >-
            This app sets up a simple linux container with "rsync". The rsync process checks to see if there is any new files to be downloaded, and it downloads them immediately.
            ** IMPORTANT: ** Make sure `rsync` is installed on the remote machine. If you're SSHing into a container, make sure `rsync` is installed in the container.
        end: >-
            The container is built and deployed. You can view the logs by going to Apps > $$cap_appname > deployment tab
    displayName: RSync Container
    isOfficial: false
    description: Just a simple container that has runs rsync to download content periodically
