$30 off During Our Annual Pro Sale. View Details »

Working with Workspace

Oliver Davies
February 02, 2021

Working with Workspace

Oliver Davies

February 02, 2021
Tweet

More Decks by Oliver Davies

Other Decks in Technology

Transcript

  1. Working with
    Workspace
    Oliver Davies, Inviqa

    View Slide

  2. What is Workspace?
    • A tool that we use and maintain at Inviqa
    • Primarily for building and managing Docker Compose environments
    • Built on Symfony
    • Create custom commands for your project environments
    • Alternative to a bash script or a Makefile
    • And more...
    @opdavies

    View Slide

  3. Features
    • Commands
    • Functions
    • Attributes
    • Encrypting/decrypting secrets
    • Generating configuration files
    • Global services: logging, mail, proxy
    @opdavies

    View Slide

  4. Installation
    # Download from GitHub.
    wget https://github.com/my127/workspace/releases/download/0.1.3/ws
    # Make it executable.
    chmod +x ws
    # Make it accessible.
    mv ws /usr/local/bin
    @opdavies

    View Slide

  5. @opdavies

    View Slide

  6. Replacing your Makefile
    @opdavies

    View Slide

  7. Running simple commands
    1 # workspace.yml
    2
    3 workspace('oliverdavies-uk'):
    4 description: My personal website codebase.
    5
    6 command('say-hello'):
    7 #!bash
    8 echo 'Hello world'
    9
    10 command('say-hello'):
    11 #!php
    12 echo 'Hello World';
    @opdavies

    View Slide

  8. @opdavies

    View Slide

  9. 'run' vs. 'passthru'
    command('say-hello'):
    #!bash
    run echo 'Hello World'
    passthru echo 'Hello World'
    @opdavies

    View Slide

  10. Attributes
    1 attribute('message'): Hello World!
    2
    3 command('say-hello'): |
    4 #!bash|@
    5 echo @('message')
    @opdavies

    View Slide

  11. Arguments
    1 command('say-hello '): |
    2 #!bash|=
    3 echo ={ @('message') } from ={ input.argument('name') }
    @opdavies

    View Slide

  12. Environment variables
    1 command('say-hello '):
    2 env:
    3 MESSAGE: = @('message')
    4 NAME: = input.argument('name')
    5 exec: |
    6 #!bash|=
    7 echo "$MESSAGE from $NAME"
    @opdavies

    View Slide

  13. Managing secrets
    # ws secret generate-random-key
    key('default'): 'd38be3b7aa42fdbfb14c0d25f07bc1875edd5f13f640cd76'
    # ws secret encrypt 'Hello World!'
    attribute('message'): = decrypt('YTozOntpOjA7czo3OiJkZWZhdWx0Ijt')
    command('say-hello'): |
    #!bash|@
    echo @('message')
    @opdavies

    View Slide

  14. Example: building slides from
    rst2pdf
    @opdavies

    View Slide

  15. Attributes
    attributes:
    rst2pdf:
    command: |
    = 'rst2pdf ' ~ @('rst2pdf.filename.rst') ~ '
    --break-level 1
    --stylesheets main
    --fit-background-mode scale
    --extension-module preprocess
    --output ' ~ @('rst2pdf.filename.pdf')
    filename:
    pdf: slides.pdf
    rst: slides.rst
    thumbnail:
    filename: thumbnail.png
    @opdavies

    View Slide

  16. Generating PDFs
    command('pdf generate '): |
    #!bash|=
    cd ={ input.argument('talk') }
    passthru ={ @('rst2pdf.command') }
    command('pdf watch '): |
    #!bash|=
    cd ={ input.argument('talk') }
    passthru nodemon -e rst,style,txt -x "={ @('rst2pdf.command') }"
    @opdavies

    View Slide

  17. Generating thumbnails
    command('thumbnail '):
    env:
    PDF_FILENAME: = @('rst2pdf.filename.pdf')
    THUMBNAIL_FILENAME: = @('thumbnail.filename')
    exec: |
    #!bash|=
    cd ={ input.argument('talk') }
    passthru gs -sDEVICE=png16m -r300 -dDownScaleFactor=4
    -sOutputFile=$THUMBNAIL_FILENAME -dLastPage=1 $PDF_FILENAME
    @opdavies

    View Slide

  18. Configuration files
    @opdavies

    View Slide

  19. Using confd
    1 attributes:
    2 drupal:
    3 docroot: web
    4
    5 command('apply config'): |
    6 #!php
    7 $ws->confd('workspace:/confd')->apply();
    8
    9 confd('workspace:/confd'):
    10 - src: 'vhost.conf'
    11 dst: 'workspace:/.my127ws/docker/nginx/default.conf'
    @opdavies

    View Slide

  20. vhost.conf.twig
    The source file.
    1 server {
    2 server_name _;
    3 root /app/{{ @('drupal.docroot' )}};
    4
    @opdavies

    View Slide

  21. default.conf
    The generated file.
    1 server {
    2 server_name _;
    3 root /app/web;
    4
    @opdavies

    View Slide

  22. Demo: "Workspacing" my site
    @opdavies

    View Slide

  23. Thanks!
    References:
    • https://github.com/my127/workspace
    • https://oliverdavies.link/workspace-demo
    • https://oliverdavies.link/workspacing-site
    Me:
    • https://www.oliverdavies.uk
    @opdavies

    View Slide