Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker based welcome.openstreetmap.org #566

Closed
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
1 change: 1 addition & 0 deletions .github/workflows/test-kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- foundation-dwg
- foundation-mwg
- foundation-owg
- foundation-welcome
- foundation-wiki
- ftp
- geodns
Expand Down
3 changes: 3 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ suites:
- name: foundation-owg
run_list:
- recipe[foundation::owg]
- name: foundation-welcome
run_list:
- recipe[foundation::welcome]
- name: foundation-wiki
run_list:
- recipe[foundation::wiki]
Expand Down
1 change: 1 addition & 0 deletions cookbooks/foundation/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
version "1.0.0"
supports "ubuntu"
depends "apache"
depends "docker"
depends "git"
depends "mediawiki"
depends "ruby"
66 changes: 66 additions & 0 deletions cookbooks/foundation/recipes/welcome.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
# Cookbook:: foundation
# Recipe:: welcome
#
# Copyright:: 2023, OpenStreetMap Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "apache"
include_recipe "docker"

docker_external_port = 8090
docker_image = "ghcr.io/osmfoundation/welcome-mat:latest"

systemd_service "docker_welcome-mat" do
description "Docker service for welcome.openstreetmap.org"
requires "docker.service"
# Ensure Container is completely stopped and removed before starting it again
exec_start_pre [
"-/usr/bin/docker kill welcome-mat",
"-/usr/bin/docker rm welcome-mat"
]
exec_start "/usr/bin/docker run --rm --name=welcome-mat --user 33:33 -p #{docker_external_port}:8080 #{docker_image}"
# Ensure Container is completely stopped and removed
exec_stop [
"-/usr/bin/docker kill welcome-mat",
"-/usr/bin/docker rm welcome-mat"
]
restart "always"
end

# FIXME: this should be a docker_image resource
# The image pull is handled by the service but container test will fail if the container startup is delayed by slow pull
execute "docker_pull_welcome_mat" do
command "/usr/bin/docker pull #{docker_image}"
action :nothing
subscribes :run, "systemd_service[docker_welcome-mat]"
end

service "docker_welcome-mat" do
action [:enable, :start]
subscribes :restart, "systemd_service[docker_welcome-mat]"
end

ssl_certificate "welcome.openstreetmap.org" do
domains ["welcome.openstreetmap.org", "welcome.osm.org"]
notifies :reload, "service[apache2]"
end

apache_module "proxy_http"

apache_site "welcome.openstreetmap.org" do
template "apache.welcome.erb"
variables :docker_external_port => docker_external_port, :aliases => ["welcome.osm.org"]
end
38 changes: 38 additions & 0 deletions cookbooks/foundation/templates/default/apache.welcome.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# DO NOT EDIT - This file is being maintained by Chef

<VirtualHost *:443>
ServerName <%= @name %>
<% @aliases.each do |alias_name| -%>
ServerAlias <%= alias_name %>
<% end -%>
ServerAdmin [email protected]

CustomLog /var/log/apache2/<%= @name %>-access.log combined
ErrorLog /var/log/apache2/<%= @name %>-error.log

SSLEngine on
SSLCertificateFile /etc/ssl/certs/<%= @name %>.pem
SSLCertificateKeyFile /etc/ssl/private/<%= @name %>.key

# Let the backend know we are using HTTPS
RequestHeader set X-Forwarded-Proto “https”
RequestHeader set X-Forwarded-Port “443”

ProxyPass / http://localhost:<%= @docker_external_port %>/
ProxyPreserveHost on

</VirtualHost>

<VirtualHost *:80>
ServerName <%= @name %>
<% @aliases.each do |alias_name| -%>
ServerAlias <%= alias_name %>
<% end -%>
ServerAdmin [email protected]

CustomLog /var/log/apache2/<%= @name %>-access.log combined
ErrorLog /var/log/apache2/<%= @name %>-error.log

RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/
RedirectPermanent / https://<%= @name %>/
</VirtualHost>
21 changes: 21 additions & 0 deletions test/integration/foundation-welcome/serverspec/apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "serverspec"

# Required by serverspec
set :backend, :exec

describe package("apache2") do
it { should be_installed }
end

describe service("apache2") do
it { should be_enabled }
it { should be_running }
end

describe port(80) do
it { should be_listening.with("tcp") }
end

describe port(443) do
it { should be_listening.with("tcp") }
end
18 changes: 18 additions & 0 deletions test/integration/foundation-welcome/serverspec/docker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "serverspec"

# Required by serverspec
set :backend, :exec

describe package("docker-ce") do
it { should be_installed }
end

describe service("docker") do
it { should be_enabled }
it { should be_running }
end

describe docker_container("welcome-mat") do
it { should exist }
it { should be_running }
end