Code Monkey home page Code Monkey logo

dockerc's Introduction

Docker Compose Wrapper CLI

CLI wrapper for docker build and run services based on docker-compose.yaml in frontend project.

The only thing we concern is the dynamic version number.

oclif CircleCI GitHub license

Prerequisites

  • Docker installed
  • Docker compose installed - Can use docker compose command
  • Docker Service started
  • docker-compose.yaml file existed in cwd

Features

  • Image version existence check
  • Use semver version
  • Use name and version fields of package.json default

Installation

npm i -g dockerc

Usage

Assume that there is the following Dockerfile file:

FROM nginx:1.24.0-alpine-slim

COPY --chown=nginx:nginx ./dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/templates/default.conf.template

ARG VERSION="v0.0.0"
ENV VERSION=${VERSION}

And the following docker-compose.yaml file:

version: "3"
services:
  build:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VERSION: ${VERSION}
    image: ${IMAGE_NAME}:${VERSION}

  dev:
    image: nginx:1.24.0
    container_name: example-dev
    restart: unless-stopped
    volumes:
      - ./dist:/usr/share/nginx/html
      - ./nginx.conf:/etc/nginx/templates/default.conf.template
    ports:
      - 8080:80

  prod:
    image: ${IMAGE_NAME}:${VERSION}
    container_name: example-prod
    restart: unless-stopped
    ports:
      - 80:80

Commands

dockerc build

Build docker images with build service in docker-compose.yaml file.

USAGE
  $ dockerc build [--image <value>] [--no-export] [--version <value>]

FLAGS
  --image=<value>    Docker image name. Use the `name` field of the `package.json` file in CWD.
  --no-export        Don't export image after the docker build is successful.
  --version=<value>  Docker image version. Use the `version` field of the `package.json` file in CWD.

DESCRIPTION
  Build docker images with `build` service in `docker-compose.yaml` file.
  It will inject `IMAGE_NAME` and `VERSION` environment variables.

EXAMPLES
  $ dockerc build    # Use the `name` and `version` field of the `package.json` file in CWD.

  $ dockerc build --image example    # Specify image name

  $ dockerc build --version 1.0.0    # Specify image version

See code: src/commands/build.ts

dockerc dev

Start dev service in docker-compose.yaml file.

USAGE
  $ dockerc dev

DESCRIPTION
  Start `dev` service in `docker-compose.yaml` file.

EXAMPLES
  $ dockerc dev

See code: src/commands/dev.ts

dockerc help [COMMANDS]

Display help for dockerc.

USAGE
  $ dockerc help [COMMANDS] [-n]

ARGUMENTS
  COMMANDS  Command to show help for.

FLAGS
  -n, --nested-commands  Include all nested commands in the output.

DESCRIPTION
  Display help for dockerc.

See code: @oclif/plugin-help

dockerc prod

Start prod service in docker-compose.yaml file.

USAGE
  $ dockerc prod [--image <value>]

FLAGS
  --image=<value>  Docker image name. Use the `name` field of the `package.json` file in CWD.

DESCRIPTION
  Start `prod` service in `docker-compose.yaml` file.
  The docker image will be selected from the existing image list
  It will inject `IMAGE_NAME` and `VERSION` environment variables.

EXAMPLES
  $ dockerc prod    # Use the `name` field of the `package.json` file in CWD.

  $ dockerc prod --image example    # Specify image name

See code: src/commands/prod.ts

Integration

# .release-it.yaml
# omit other configuration
hooks:
  "after:release": "dockerc build --version ${version}"

Development

Clone the repository

git clone https://github.com/jxsylar/dockerc

Install dependencies

pnpm i

Also, It will run build automatic.

Install CLI global

npm link

It will install to $(npm prefix root -g)/bin/ folder, make sure this path is in PATH env.

Now you can use dockerc command in your shell:

docker

Update

After code changed, build again:

pnpm run build

And the dockerc command will automatic use the latest version, which means you don't need to run npm link again.

Document

Automatically update README.md by running:

pnpm run doc

Note: The command must run after building.

Uninstall

npm unlink -g dockerc

This command can run in any path, which means you don't need to cd the project path.

Reference

Docker compose file variable interpolation

dockerc's People

Contributors

jxsylar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.