Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:

jobs:
Spec:
uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@main"
uses: "puppetlabs/cat-github-actions/.github/workflows/module_ci.yml@ubuntu-22-test"
with:
runs_on: "ubuntu-24.04"
secrets: "inherit"

Acceptance:
needs: Spec
uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@main"
uses: "puppetlabs/cat-github-actions/.github/workflows/module_acceptance.yml@ubuntu-22-test"
with:
flags: '--provision-prefer provision_service --provision-exclude docker --arch-exclude arm --puppetlabs --nightly'
secrets: "inherit"
3 changes: 3 additions & 0 deletions lib/puppet/provider/docker_compose/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def exists?

compose_services = compose_output['services']

# Remove services with restart: 'no' from the compose_services list as they are not expected to be running.
compose_services.reject! { |_k, v| v['restart'] == 'no' }

return false if compose_services.count != compose_containers.uniq.count

counts = Hash[*compose_services.each.map { |key, array|
Expand Down
25 changes: 0 additions & 25 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,11 @@
}
],
"operatingsystem_support": [
{
"operatingsystem": "CentOS",
"operatingsystemrelease": [
"7",
"8",
"9"
]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": [
"18.04",
"20.04",
"22.04"
]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": [
"10",
"11"
]
},
{
"operatingsystem": "Windows",
"operatingsystemrelease": [
"2016",
"2019",
"2022"
]
}
],
"requirements": [
Expand Down
37 changes: 37 additions & 0 deletions spec/acceptance/compose_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,43 @@ class { 'docker::compose': }
end
end

context 'Creating compose projects with services having restart: no' do
before(:all) do
# Create a compose file with one service having restart: no
compose_content = <<-YAML
version: '3.8'
services:
db:
image: mysql:5.7
restart: always
web:
image: nginx
restart: no
YAML
create_remote_file(hosts, "#{tmp_path}/docker-compose-restart-no.yml", compose_content)
end

let(:install_pp) do
<<-MANIFEST
docker_compose { 'restart_test':
compose_files => ['#{tmp_path}/docker-compose-restart-no.yml'],
ensure => present,
}
MANIFEST
end

it 'is idempotent' do
idempotent_apply(install_pp)
end

it 'finds the running service but ignores the restart: no service' do
# Assuming the compose file has one service with restart: always and one with restart: no
run_shell('docker inspect restart_test-db_1', expect_failures: false)
# The web service with restart: no should not be running
run_shell('docker inspect restart_test-web_1', expect_failures: true)
end
end

context 'Requesting a specific version of compose' do
let(:version) do
'2.25.0'
Expand Down
36 changes: 36 additions & 0 deletions spec/unit/lib/puppet/provider/docker_compose/ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'spec_helper'

describe Puppet::Type.type(:docker_compose).provider(:ruby) do
let(:resource) do
Puppet::Type.type(:docker_compose).new(
name: 'test_project',
compose_files: ['/tmp/docker-compose.yml'],
provider: :ruby,
)
end

let(:provider) { resource.provider }

describe '#exists?' do
before(:each) do
allow(Puppet::Util::Platform).to receive(:windows?).and_return(false)
allow(provider).to receive(:execute).and_return(YAML.safe_load("services:\n web:\n image: mysql\n restart: always\n"))
allow(provider).to receive(:docker).and_return("'db-mysql'\n")
end

it 'ignores services with restart: no' do
# Mock the compose_output to have services with restart: 'no'
allow(Puppet::Util::Yaml).to receive(:safe_load).and_return({
'services' => {
'web' => { 'image' => 'nginx', 'restart' => 'no' },
'db' => { 'image' => 'mysql', 'restart' => 'always' }
}
})

# Only db should be considered, and it matches the running container
expect(provider.exists?).to be true
end
end
end