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 the DNS mapping migration #6529

Merged
merged 18 commits into from Jan 2, 2024
Merged

Add the DNS mapping migration #6529

merged 18 commits into from Jan 2, 2024

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Nov 14, 2023

Alternative approach to #4077 and #4583. This allows you to define mappings via a DNS_MAPPING environment variable which will update the dns entries for all given domains to the updated domain in the database during migrations.

# .env.local in your local environment
DNS_MAPPING='{
    "www.example.com": "example.local",
    "www.foobar.org": "foobar.local",
    "www.lorem.at": "lorem.local"
}'
# .env.local in your staging environment
DNS_MAPPING='{
    "www.example.com": "staging.example.com",
    "www.foobar.org": "staging.foobar.org",
    "www.lorem.at": "staging.lorem.at"
}'

This allows you to - for example - copy the live database to your staging or local environment and then automatically change the domains according to the mapping in the respective environment during contao:migrate.

As a bonus you can also migrate the useSSL setting to different settings in the respective environment, which might be useful if you haven't set up an SSL certificate in your local development environment.

DNS_MAPPING='{
    "www.example.com": "http://example.local",
    "www.foobar.org": "http://foobar.local",
    "www.lorem.at": "http://lorem.local"
}'

This also works if you do not use a dns name in some of your website roots (although that is not a recommended setup).

DNS_MAPPING='{
    "": "http://",
    "www.foobar.org": "http://foobar.local",
    "www.lorem.at": "http://lorem.local"
}'
DNS_MAPPING='{
    "": "example.local",
    "www.foobar.org": "foobar.local",
    "www.lorem.at": "lorem.local"
}'

Instead of the environment variable, you can also directly set the parameter in your parameters.yaml (or wherever):

parameters:
    contao.dns_mapping:
        www.example.com: http://example.local
        www.foobar.org: http://foobar.local
        www.lorem.at: http://lorem.local

@fritzmg fritzmg added this to the 5.3 milestone Nov 14, 2023
@fritzmg fritzmg self-assigned this Nov 14, 2023
Toflar
Toflar previously approved these changes Nov 14, 2023
Toflar
Toflar previously approved these changes Nov 14, 2023
ausi
ausi previously approved these changes Nov 15, 2023
@aschempp aschempp mentioned this pull request Nov 21, 2023
@leofeyer leofeyer dismissed stale reviews from ausi and Toflar via 86b3b13 November 21, 2023 16:18
@fritzmg
Copy link
Contributor Author

fritzmg commented Dec 10, 2023

As discussed in the last call, the definition of the environment variable has now been moved to the Manager Bundle. However, it is not possible to also provide this as a bundle configuration, as you cannot reference an environment variable for array config nodes yet (see symfony/symfony#40906). Thus this is again solely based on a contao.dns_mapping parameter.

The core bundle checks whether such a parameter has been defined in the container and if not sets an empty default. The manager bundle also checks whether such a parameter has been defined in the container (e.g. in the App) and if not sets it to the DNS_MAPPING environment variable.

@fritzmg
Copy link
Contributor Author

fritzmg commented Dec 10, 2023

In a non-managed edition you will have to add this to your config (if you want to use an environment variable for the parameter):

parameters:
    env(DNS_MAPPING): []
    contao.dns_mapping: '%env(json:DNS_MAPPING)%'

Toflar
Toflar previously approved these changes Dec 11, 2023
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally add a TODO and link to the Symfony issue so that we can get rid of the workaround if this was fixed eventually but other than that 👍

Toflar
Toflar previously approved these changes Dec 11, 2023
@leofeyer leofeyer added the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Dec 13, 2023
ausi
ausi previously approved these changes Dec 14, 2023
Co-authored-by: Martin Auswöger <martin@auswoeger.com>
ausi
ausi previously approved these changes Dec 14, 2023
@leofeyer leofeyer removed the up for discussion Issues and PRs which will be discussed in our monthly Mumble calls. label Dec 14, 2023
@fritzmg fritzmg requested a review from ausi December 14, 2023 17:31
@fritzmg
Copy link
Contributor Author

fritzmg commented Dec 14, 2023

As discussed in the Contao call today, the contao.dns_mapping parameter definition has now been moved to the migrations.yaml with its default empty value. And the contao.dns_mapping parameter override via the DNS_MAPPING environment variable has been moved to the skeleton config in the Manager Bundle.

ausi
ausi previously approved these changes Dec 14, 2023
@leofeyer leofeyer changed the title Add DNS mapping migration Add the DNS mapping migration Jan 2, 2024
@leofeyer leofeyer enabled auto-merge (squash) January 2, 2024 17:36
@leofeyer
Copy link
Member

leofeyer commented Jan 2, 2024

Thank you @fritzmg.

@leofeyer leofeyer merged commit e9e8457 into contao:5.x Jan 2, 2024
16 checks passed
@fritzmg fritzmg deleted the dns-mapping branch April 19, 2024 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants