Commands for creating a Web App #
💡 You can replace the default values of the commands forPROJECT,STAGEandAPPNAMEin the form on the right side! A standard pattern might bemyproject,productionandweb(see concepts).
We recommend creating shortcuts for the commands setops and setops -p <PROJECT> -s <STAGE>. See our best practices for setting an Alias.
Create Project and Stage #
setops -p <PROJECT> project:create
setops -p <PROJECT> -s <STAGE> stage:create
Create Required Secret #
setops -p <PROJECT> -s <STAGE> secret:create secret_key_base=$(openssl rand -hex 64)
Create Stage Definition #
apps:
    <APPNAME>:
        container:
            command:
                - bundle
                - exec
                - rackup
                - --host
                - 0.0.0.0
                - --port
                - "5000"
            health_check:
                command:
                    - wget
                    - -qO-
                    - http://localhost:5000/.well-known/health-check
                interval: 30
                retries: 5
                start_period: 15
                timeout: 10
        custom_domains:
            zwei.beer:
                primary: false
                redirect_to_primary: false
                static_ips: false
                validated: true
        env:
            RACK_ENV:
                description: The Rack environment
                value: production
            SECRET_KEY_BASE:
              description: The secret key base used for encrypting sessions in Rails
              value: "{{ .Secrets.secret_key_base }}"
        links:
            my-app-data-store1:
                env_key: S3_DATA_URL
            my-app-documentdb1:
                env_key: MONGODB_URL
            my-app-es-engine01:
                env_key: ELASTICSEARCH_URL
            my-app-local-data1:
                path: /data-write
                read_only: false
            my-app-local-data2:
                path: /data-read
                read_only: true
            my-app-postgresql1:
                env_key: DATABASE_URL
            my-app-postgresql2:
                env_key: DEDICATED_DATABASE_URL
            my-app-redis-data1:
                env_key: REDIS_URL
        network:
            health_check:
                path: /.well-known/health-check
                status: "200"
            ports:
                - 5000
            protocol: http
            public: true
        resources:
            cpu: 256
            memory: 512
            scale: 1
notifications:
    ops-my-genie:
        target: https://api.eu.opsgenie.com/v1/json/cloudwatch?apiKey=<APIKEY>
        type: webhook
project: <PROJECT>
schema_version: "2"
services:
    my-app-data-store1:
        options: {}
        type: s3
    my-app-documentdb1:
        options:
            scale: 1
        plan: db.t3.medium
        type: documentdb
        version: "4"
    my-app-es-engine01:
        options:
            storage: 10
        plan: t3.small.elasticsearch
        type: elasticsearch
        version: "7"
    my-app-local-data1:
        options: {}
        type: volume
    my-app-local-data2:
        options: {}
        type: volume
    my-app-postgresql1:
        options:
            extensions:
                - postgis
                - pgcrypto
        plan: shared
        type: postgresql
    my-app-postgresql2:
        options:
            extensions:
                - postgis
                - pgcrypto
            max_storage: 25
            min_storage: 20
        plan: db.t3.micro
        type: postgresql
        version: "16.4"
    my-app-redis-data1:
        options: {}
        plan: cache.t2.micro
        type: redis
        version: "7.1"
stage: <STAGE>
Push and activate image #
First, you need to build a container image for your application. Then push it to the SetOps container image registry. Look at best practices for building an image
setops -p <PROJECT> -s <STAGE> --app <APPNAME> image:push --tag v1.0.0 --from-image myimage
setops -p <PROJECT> -s <STAGE> stage:apply --image-tags <APPNAME>=v1.0.0
Check Running App #
setops -p <PROJECT> -s <STAGE> --app <APPNAME> task
Check Health Status #
If RUNNING & HEALTHY ✅ Now you can open the website at:
https://<APPNAME>.<STAGE>.<PROJECT>.<YOURDOMAIN>/
Logs #
setops -p <PROJECT> -s <STAGE> --app <APPNAME> log
setops -p <PROJECT> -s <STAGE> --app <APPNAME> log -f
setops -p <PROJECT> -s <STAGE> --app <APPNAME> log -f | egrep -v '/.well-known/health-check'  # to filter out Health Check logs
One-Off Tasks #
setops -p <PROJECT> -s <STAGE> --app <APPNAME> task:run -- echo "Hello World"
setops -p <PROJECT> -s <STAGE> --app <APPNAME> task:run -- bundle exec rake db:migrate
setops -p <PROJECT> -s <STAGE> --app <APPNAME> task:run --interactive -- echo "Hello World"
Upload Database & S3 Data #
See Backup & Restore for further information.
setops -p <PROJECT> -s <STAGE> --service <SERVICE> backup
setops -p <PROJECT> -s <STAGE> --service <SERVICE> backup:upload </path/to/my/backup>
setops -p <PROJECT> -s <STAGE> --service <SERVICE> backup            # copy the ID of the latest manual backup
setops -p <PROJECT> -s <STAGE> --service <SERVICE> backup:restore <ID>
Add Worker and other App-Container #
If your application uses background tasks like delayed-job, sidekiq, or clockwork, you need to create a separate App for that.
- Create the app (workermight be a good name)
- Set container settings (Health Check is not needed if the app is private)
- Set all required ENV
- Link required services (like database or queue)
- Push and activate the same image
