Skip to content
Merged
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/pullpreview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
instance_type: micro
# only required if using custom domain for your preview environments
dns: custom.pullpreview.com
max_domain_length: 30
# only required if fetching images from private registry
registries: docker://${{ secrets.GHCR_PAT }}@ghcr.io
# how long this instance will stay alive (each further commit will reset the timer)
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
dns:
description: "Which DNS suffix to use"
default: "my.pullpreview.com"
max_domain_length:
description: "Maximum length of fully qualified domain name. Note that it cannot be greater than 62 characters due to LetsEncrypt restrictions."
default: "62"
label:
description: "Label to use for triggering preview deployments"
default: "pullpreview"
Expand Down Expand Up @@ -120,3 +123,4 @@ runs:
GITHUB_TOKEN: "${{ inputs.github_token }}"
PULLPREVIEW_LICENSE: "${{ inputs.license }}"
PULLPREVIEW_PROVIDER: "${{ inputs.provider }}"
PULLPREVIEW_MAX_DOMAIN_LENGTH: "${{ inputs.max_domain_length }}"
23 changes: 18 additions & 5 deletions lib/pull_preview/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

module PullPreview
class Instance
# https://community.letsencrypt.org/t/a-certificate-for-a-63-character-domain/78870/4
DEFAULT_MAX_DOMAIN_LENGTH = 62

include Utils

attr_reader :admins
Expand Down Expand Up @@ -79,14 +82,24 @@ def public_ip
access_details.ip_address
end

def max_domain_length
value = ENV.fetch("PULLPREVIEW_MAX_DOMAIN_LENGTH", DEFAULT_MAX_DOMAIN_LENGTH).to_i
value = DEFAULT_MAX_DOMAIN_LENGTH if value <= 0 || value > DEFAULT_MAX_DOMAIN_LENGTH
value
end

# Leave 8 chars for an additional subdomain that could be needed by the deployed app.
# Disabled if custom domain length is specified.
def reserved_space_for_user_subdomain
max_domain_length != DEFAULT_MAX_DOMAIN_LENGTH ? 0 : 8
end

def public_dns
reserved_space_for_user_subdomain = 8
# https://community.letsencrypt.org/t/a-certificate-for-a-63-character-domain/78870/4
remaining_chars_for_subdomain = 62 - reserved_space_for_user_subdomain - dns.size - public_ip.size - "ip".size - ("." * 3).size
remaining_chars_for_subdomain = max_domain_length - reserved_space_for_user_subdomain - dns.size - public_ip.size - "ip".size - ("." * 3).size
[
[subdomain[0..remaining_chars_for_subdomain], "ip", public_ip.gsub(".", "-")].join("-").squeeze("-"),
[subdomain[0..[(remaining_chars_for_subdomain - 1), 0].max], "ip", public_ip.gsub(".", "-")].join("-").squeeze("-"),
dns
].join(".")
].reject{|part| part.empty?}.join(".")
end

def url
Expand Down