Skip to content

Commit

Permalink
Add workflow file
Browse files Browse the repository at this point in the history
Add is-ready check on the default files tests
Add a check the entrypoint is not still running (slightly different case to the ready file that gets added on first boot)
  • Loading branch information
MattGrundy authored and JakeBiddell committed Aug 27, 2024
1 parent 3e9b327 commit 38ddee2
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 97 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Spec tests

on:
push:
branches:
- main

pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
run_test_suite:
name: Run test suite
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Earthly
uses: earthly/actions-setup@v1
with:
version: 0.8.14

- name: Run tests
run: |
earthly -P ./test+test
301 changes: 205 additions & 96 deletions test/serverspec/spec/always/paths_spec.rb
Original file line number Diff line number Diff line change
@@ -1,101 +1,210 @@
require 'spec_helper'

describe file('/etc/php/8.3') do
it { should exist }
it { should be_directory }
describe "Default file checks" do
before(:all) do
system('/usr/local/bin/is-ready --check-entrypoint --check-tasks --wait --timeout 60 -v') or raise "is-ready failed"
end

describe file('/etc/php/8.3') do
it { should exist }
it { should be_directory }
end

describe file('/usr/local/share/deskpro/container-var-reference.json') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content_as_json) { should_not be_empty }
end

describe file('/usr/local/share/deskpro/container-public-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-private-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-setenv-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/phpinfo.php') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/var/log/nginx') do
it { should be_directory }
it { should be_owned_by 'nginx' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/php') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/deskpro') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/lib/vector') do
it { should be_directory }
it { should be_owned_by 'vector' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA/deskpro-config.d') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/services/messenger-api/.env') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-var-reference.json') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content_as_json) { should_not be_empty }
end

describe file('/usr/local/share/deskpro/container-public-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-private-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-setenv-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/phpinfo.php') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/var/log/nginx') do
it { should be_directory }
it { should be_owned_by 'nginx' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/php') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/deskpro') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/lib/vector') do
it { should be_directory }
it { should be_owned_by 'vector' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA/deskpro-config.d') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end
end

describe file('/usr/local/share/deskpro/container-var-reference.json') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
its(:content_as_json) { should_not be_empty }
end

describe file('/usr/local/share/deskpro/container-public-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-private-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-setenv-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/container-var-list') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/usr/local/share/deskpro/phpinfo.php') do
it { should exist }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end

describe file('/var/log/nginx') do
it { should be_directory }
it { should be_owned_by 'nginx' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/php') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/log/deskpro') do
it { should be_directory }
it { should be_owned_by 'dp_app' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/var/lib/vector') do
it { should be_directory }
it { should be_owned_by 'vector' }
it { should be_grouped_into 'adm' }

it { should be_readable.by('owner') }
it { should be_readable.by('group') }
it { should be_writable.by('owner') }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end

describe file('/srv/deskpro/INSTANCE_DATA/deskpro-config.d') do
it { should be_directory }
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
it { should_not be_writable.by('others') }
end
17 changes: 16 additions & 1 deletion test/serverspec/spec/default_web/utils/is-ready_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
FileUtils.touch('/run/container-ready')
FileUtils.remove_file('/run/container-running-installer', true)
FileUtils.remove_file('/run/container-running-migrations', true)
FileUtils.remove_file('/run/container-running-entrypoint', true)
end

it "Blocks when using --wait", :slow do
Expand Down Expand Up @@ -87,10 +88,24 @@
expect(exit_code).to eq 0
end

it "Post-boot tasks matter with --check-tasks" do
it "Post-boot migration tasks matter with --check-tasks" do
FileUtils.touch('/run/container-running-migrations')
system('is-ready --check-tasks')
exit_code = $?.exitstatus
expect(exit_code).to eq 1
end

it "Post-boot installer tasks matter with --check-tasks" do
FileUtils.touch('/run/container-running-installer')
system('is-ready --check-tasks')
exit_code = $?.exitstatus
expect(exit_code).to eq 1
end

it "Post-boot entrypoint tasks matter with --check-tasks" do
FileUtils.touch('/run/container-running-entrypoint')
system('is-ready --check-tasks')
exit_code = $?.exitstatus
expect(exit_code).to eq 1
end
end
6 changes: 6 additions & 0 deletions usr/local/bin/is-ready
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ check_ready() {
return 1
fi


if [ "$check_tasks" = "1" ]; then
if [ -f "/run/container-running-entrypoint" ]; then
output "Entrypoint initialisation is running"
return 1
fi

if [ -f "/run/container-running-installer" ]; then
output "Installer is running"
return 1
Expand Down
Loading

0 comments on commit 38ddee2

Please sign in to comment.