Skip to content

Latest commit

History

183 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Compote

Docker-based tool to run services.

The aim of this is not to apply the best standards or be super performant but rather a simple solution for git-push deployment of containers on own servers.

Each project is represented as a "compote jar" - a dedicated directory that holds configuration and git source code, optionally cached libraries, data to be persisted, etc.

You define your own scripts inside the project, which do all the necessary work before a release docker image can be built and the container run. These scripts are run as the deployer user.

Is it any good?

yes

Requirements

system

GNU/Linux, bash. Developed on Ubuntu server 22.04.

sudo

This tool expects that you access the server as a non-root user with password-less sudo provided.

docker

this tool is docker-based, please head to docker install docs to install it.

ruby

System-wide installation with the following gems required. Developed with 3.0 version.

sudo apt install ruby
sudo gem install colorize tty-prompt dotenv

Install

ssh to the server and download compote:

sudo git clone https://github.com/doooby/compote.git /opt/compote

As the deployer user, that has sudo access:

# always read and understand the script before you run it!
/opt/compote/bin/user_install.rb
# log off and on again# now you can run compote using alias
compote ls

Use

Before creating new compote jar on the server, you need have some config files in your repository. see next section for details.

This example is for Ruby on Rails application.

  • note it will take considerable more time to run for the first time commands like update and brew. It will download docker images and in this case also ruby gems.
  • run build_base creates a base image that is neccessary to:
    • build the release one
    • install ruby gems
    • build assets
  • brew will fail for the first time on missing database. Just import/restore using postgresql tools or create new one. Then run the brew command again.
  • compose is there to simply run one-off app instances to do stuff like database imports, rake tasks, etc.
compote new app
# which print as last line: `git repository path: /var/compote_shelf/app/.git`# add this as a remote and `git push` to it
jar app config # set environment variables in `.env` (all build and runtime processes inherits these)
jar app update # updates the source code internaly
jar app run build_base # runs .compote/scripts/build_base.rb
jar app brew # deploy, i.e. it runs .compote/scripts/brew.rb# for automatic deploys via git "post-receive" hook
jar app auto_brew 1
# spin up app container to check
jar app compose run --rm app bash

compote configuration for a repository

Create ./.compote directory.

# .compote/docker-compose.ymlservices:
app:
image: jar--${JAR_NAME}:releaseenv_file:
- ${JAR_PATH}/.envcommand: bash -c "rm -f tmp/pids/server.pid && bin/rails s -p 3000"restart: unless-stoppeddepends_on:
- pgports:
- ${APP_SERVICE_PORT}:3000volumes:
- ${JAR_PATH}/var/ruby_bundle:/usr/local/bundle
- ${JAR_PATH}/var/log:/app/logpg:
image: postgres:17environment:
POSTGRES_HOST_AUTH_METHOD: trustrestart: unless-stoppedshm_size: 100mbvolumes:
- ${JAR_PATH}/var/pg_data:/var/lib/postgresql/data
# .compote/app.base.DockerfileFROM ruby:3.3.5
WORKDIR /app
RUN \
apt-get -qq update && \
apt-get -qq -y install postgresql-client-17
# app.release.DockerfileARG JAR_NAME
FROM jar--${JAR_NAME}:base
COPY src .
COPY var/assets ./public/assets
# .compote/scripts/build_base.rb
$jar.with_dockerignoredoCompote.run<<-CMDsudo docker build \\ -f src/.compote/app.base.Dockerfile \\ -t jar--#{$jar.name}:base \\ .CMDend
# .compote/scripts/brew.rbCompote.log:yellow,'===== installing gems'Compote.run<<-CMDsudo docker run --rm \\ -v ./src:/app \\ -v ./var/ruby_bundle:/usr/local/bundle \\ jar--#{$jar.name}:base \\ bash -c " \\bundle config set --local without 'development test' && \\bundle install \\"CMDCompote.log:yellow,'===== building assets'Compote.run<<-CMDsudo docker run --rm \\ -v ./src:/app \\ -v ./var/ruby_bundle:/usr/local/bundle \\ -v ./var/assets:/app/public/assets \\ jar--#{$jar.name}:base \\ rails assets:precompileCMDCompote.log:yellow,'===== building docker image'dockerignore=<<-FILE!src!var/ruby_bundle!var/assetsFILE
$jar.with_dockerignoredockerignoredoCompote.run<<-CMDsudo docker build \\ -f src/.compote/app.release.Dockerfile \\ -t jar--#{$jar.name}:release \\ --build-arg JAR_NAME=#{$jar.name}\\ .CMDendCompote.log:yellow,"===== DANGER ZONE =====\n(point of no return)"Compote.run $jar.compose_cmd('run --rm app rails db:migrate')Compote.log:yellow,'===== restarting container'Compote.run $jar.compose_cmd('up -d')

About

docker-compose based stack ops

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages