Skip to content

Commit

Permalink
feat: Add Podman support
Browse files Browse the repository at this point in the history
Added `-Engine` parameter allowing to specify the container engine - either docker or podman
  • Loading branch information
iblazhko committed Apr 20, 2024
1 parent 684cdf6 commit 06cdcd4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Description

This is a tool to run set of services during development using Docker Compose.
Makes it easier to start / stop set of services on demand.
This is a tool to run set of containerized services during development.
It makes it easier to start / stop set of services on demand.

Supported services:

Expand All @@ -20,12 +20,12 @@ Supported services:

## Prerequisites

- Docker with Docker Compose CLI plugin: <https://docs.docker.com/install/>, <https://docs.docker.com/compose/install/compose-plugin/>
- Docker with Docker Compose CLI plugin (<https://docs.docker.com/install/>, <https://docs.docker.com/compose/install/compose-plugin/>) or Podman with Podman Compose CLI plugin (<https://podman.io/docs/installation>, <https://github.com/containers/podman-compose>)
- PowerShell Core: <https://github.com/powershell/powershell>

## Overview

Set of services is started using Docker Compose.
Set of services is started using Docker/Podman Compose.

Each service in the set is defined in its own directory `services/<service-name>-<version>/service.yaml`.

Expand All @@ -39,10 +39,10 @@ Sets are defined in `service-set/set.yaml` files. There are two sets provided ou
## Usage

- Clone or copy this repository locally, or download from [releases](https://github.com/iblazhko/docker-dev-services/releases/) page
- Create a service set file `service-sets/<set>.local.yaml` (there is a rule in `.gitignore` to exclude `.local.yaml` files from source control)
- Create a service set file `service-sets/<set>.local.yaml` (there is a rule in `.gitignore` to exclude `.local.yaml` files from source control); use `_template_.yaml` as a template and do not forget to change set name to something meaningful
- Review included services `service.yaml` definitions. If you need to change environment variables to a service, add file `.env/<service-name>-<version>.env`. Typically this would be used to change default credentials. See corresponding service `service.env` file for a reference.

It is recommented to organize sets by products / use cases. E.g. if *Product1* us using ELK and MongoDB, and *Product2* uses ELK, Postgres, and Redis, you may have following sets:
It is recommended to organize sets by products / use cases. E.g. if *Product1* us using ELK and MongoDB, and *Product2* uses ELK, Postgres, and Redis, you may have following sets:

`product-sets/prod1.local.yaml`

Expand Down Expand Up @@ -75,6 +75,12 @@ Start service set by name:
start.ps1 -Set <set-name>
```

By default, `docker` engine is used, if you need to use `podman` specify this using `-Engine` parameter:

```sh
start.ps1 -Set <set-name> -Engine podman
```

### Stop

Stop service set that was previously started by `start.ps1 <set-name>`.
Expand Down
21 changes: 18 additions & 3 deletions docker-dev-services.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Param(
[ValidateNotNullOrEmpty()]
[string]$Set,

[ValidateNotNullOrEmpty()]
[ValidateSet('docker', 'podman')]
[string]$Engine = 'docker',

[switch]$Force,
[switch]$Verbose
)
Expand All @@ -17,14 +21,23 @@ $rootDir = $PSScriptRoot
#######################################################################
# SINGLE INSTANCE
$activeSetFile = Join-Path $rootDir '.active-set'
if ($(Test-Path $activeSetFile)) { $activeSet = Get-Content $activeSetFile }
if ($(Test-Path $activeSetFile)) {
$activeSetContent = Get-Content $activeSetFile
$activeSetParts = $activeSetContent -Split ':'
if ($activeSetParts.Length -eq 2) {
$activeEngine = $activeSetParts[0]
$activeSet = $activeSetParts[1]
}
}

if ($activeSet) {
if ($($Action -eq 'Start') -and $($activeSet -ne $Set)) {
Write-Host "Already have active service set: $activeSet"
if (-Not $Force) { Exit 1 }
}
if ($Action -eq 'Stop') {
$Set = $activeSet
$Engine = $activeEngine
}
}
else {
Expand Down Expand Up @@ -114,10 +127,12 @@ if ($Action -eq 'Stop') { $composeArguments = $composeArguments + 'down' }
$currentLocation = Get-Location
try {
Set-Location $rootDir
if ($Verbose) { Write-Host -ForegroundColor DarkGray "docker-compose $composeArguments" }
Start-Process -FilePath "docker" -ArgumentList $composeArguments -WorkingDirectory $rootDir -NoNewWindow -Wait
if ($Verbose) { Write-Host -ForegroundColor DarkGray "compose $composeArguments" }

if ($Action -eq 'Start') { Set-Content -Path $activeSetFile $Set }
Start-Process -FilePath $Engine -ArgumentList $composeArguments -WorkingDirectory $rootDir -NoNewWindow -Wait

if ($Action -eq 'Start') { Set-Content -Path $activeSetFile "${Engine}:${Set}" }
if ($Action -eq 'Stop') { Set-Content -Path $activeSetFile '' }
}
finally {
Expand Down
20 changes: 9 additions & 11 deletions service-sets/_template.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
set: template
services:
- elasticsearch-8.3
- eventstore-5.0
- eventstore-21.10
- elasticsearch-8.12
- eventstore-23.10
- influxdb-1.8
- kibana-8.3
- logstash-8.3
- mongo-4.2
- postgres-9.6
- postgres-14.4
- rabbitmq-3.9
- kibana-8.12
- logstash-8.12
- mongo-7.0
- postgres-16.2
- rabbitmq-3.12
- redis-7.0
- seq-2022.1
- seq-2024.1
- sqlserver-2022
- vault-1.5
- vault-1.13
6 changes: 5 additions & 1 deletion start.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Param(
[ValidateNotNullOrEmpty()]
[string]$Set = 'default',

[ValidateNotNullOrEmpty()]
[ValidateSet('docker', 'podman')]
[string]$Engine = 'docker',

[switch]$Verbose
)

. $PSScriptRoot/docker-dev-services.ps1 -Set $Set -Action Start -Verbose:$Verbose
. $PSScriptRoot/docker-dev-services.ps1 -Set $Set -Action Start -Engine $Engine -Verbose:$Verbose

0 comments on commit 06cdcd4

Please sign in to comment.