I’ve been setting up most of my development environments in the last 3 years using docker and docker-compose without any important issues. Having said that, in the last couple of month I’ve repeating the following script (with some variations cases by case) in most of my projects.
#!/bin/bash case "$1" in server) docker-compose -f docker/docker-compose.yml run --rm -p 8080:8080 yarn start ;; build) docker-compose -f docker/docker-compose.yml run --rm app yarn build ;; test) docker-compose -f docker/docker-compose.yml run --rm app yarn test ;; bash) docker-compose -f docker/docker-compose.yml run --rm -p 8080:8080 server /bin/bash ;; esac
I always ended up writing a call to
docker-compose depending on the task I need to perform with some flag or arguments variations.
At the same time, I’ve spend some time working on different projects that had multiple ways of running it and lacked a simple documentation on what tasks were available inside the project.
I realized that this small script that I duplicated in most of my applications could be better expressed in a declarative fashion using a yaml file.
sdev.sh purpose is simple, Simple declarative syntax for your projects tasks.
Previous bash script is now expressed as:
version: 1 name: My Cool App description: This text should briefly mention what the application/library is about docker: compose_file: docker/docker-compose.yml tasks: - name: server description: Start the development server command: yarn start container: app rm: true ports: "8080:8080" - name: build description: This command will build the entire application and install dependencies command: yarn build container: app rm: true - name: test description: run unit test suite. command: yarn test container: app - name: bash description: ssh in docker container command: /bin/bash container: app ports: "8080:8080"
Using that yaml file as input, sdev will generate the following command for you.
➜ sdev.sh git:(improve-readme) ✗ sdev Usage: sdev [options] [command] This text should briefly mention what the application/library is about Options: -V, --version output the version number -h, --help output usage information Commands: build This command will build the entire application and install dependencies test run unit test suite. bash ssh in docker container help [cmd] display help for [cmd]
The code is open source and can be found here.
I’m looking for more cool features that could be built in sdev.sh. If you think this tool might be useful in your projects, I want to hear about it :). Ping me at [email protected]