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

feat: config cleanup finalize #1657

Merged
merged 16 commits into from
Jan 31, 2024
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
43 changes: 43 additions & 0 deletions .github/utils/config_conversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

if [ "$#" -ne 2 ]; then
echo "Usage: $0 input.yaml output.yaml"
exit 1
fi

input_file=$1
output_file=$2
ors_file="ors-api/src/test/files/heidelberg.osm.gz"

###########################
### Validate input file ###
###########################
# Fail if ors: can't be found
echo "Checking for ors section"
awk '/^ors:/{print "Found ors section"}' "$input_file" || exit 1

# For engine and source file section, make sure they are in place
echo "Checking for engine and source_file section"
awk '/ engine:/{getline; if ($0 ~ /source_file:/) {print "Found engine and source_file section"} else { exit 1 }}' "$input_file" || exit 1

# For profiles section for car wit enabled
echo "Checking for profiles section"
awk '/ profiles:/{getline; if ($0 ~ / car:/) {getline; if ($0 ~ / enabled:/) {print "Found profiles section"} else { exit 1 }}}' "$input_file" || exit 1

###########################
### Convert input file ####
###########################
# Add # to the beginning of each line that is not empty or a comment
awk '!/^[[:space:]]*#/ && !/^[[:space:]]*$/ {print "#" $0; next} {print}' "$input_file" > "$output_file"

# Replace '#ors:' with 'ors:'
sed -i 's/#ors:/ors:/g' "$output_file"


# Remove the comments for the engine and source_file section
awk -i inplace "/engine:/{getline; if (\$0 ~ /source_file:/) {print \" engine:\"; print \" source_file: '$ors_file'\"; next} else { exit1 }} {print}" "$output_file"

# Remove the comments for the profiles section for car
awk -i inplace "/# profiles:/{getline; if (\$0 ~ /# car:/) {getline; if (\$0 ~ /# enabled:/) {print \" profiles:\"; print \" car:\"; print \" enabled: true\"; next}}}{print}" "$output_file"

echo "Parsing complete. Result saved to $output_file"
1 change: 0 additions & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Build and publish the nightly Docker image
on:
pull_request:
branches: [ "main" ]
types: [ opened, synchronize, ready_for_review ]
push:
branches: [ "main" ]
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/config-conversion-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Automatic conversion of application.yml to ors-config.yml
on:
pull_request:
branches:
- main
- releases/**
types: [ edited, opened, ready_for_review, review_requested, reopened, synchronize ]
workflow_dispatch:


jobs:
detect_config_change:
name: Detect and commit config changes
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Check PR state is ready_for_review
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
pr_state=$(gh pr view --json state --jq .state)
pr_is_draft=$(gh pr view --json isDraft --jq .isDraft)
echo "pr_state=$pr_state" >> $GITHUB_ENV
echo "pr_is_draft=$pr_is_draft" >> $GITHUB_ENV
else
echo "This action is only intended to be run on pull requests."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Convert application.yml to ors-config.yml
run: |
.github/utils/config_conversion.sh ors-api/src/main/resources/application.yml ors-config.yml
- name: Check with git if ors-api/ors-config.yml has changed
id: git-check
if: env.pr_state == 'OPEN' && env.pr_is_draft == 'false'
run: |
# Don't fail on exit code 1 (diff found)
set +e
git diff --exit-code --name-only ors-api/ors-config.yml
exit_value=$?
echo Found exit code $exit_value
# Write out the exit code using environment file
if [ $exit_value == 1 ]; then
echo "config_has_changed=true" >> $GITHUB_ENV
else
echo "Config hasn't changed. Skipping commit."
fi
- uses: MichaelsJP/git-auto-commit-action@v5
if: env.pr_state == 'OPEN' && env.pr_is_draft == 'false' && env.config_has_changed == 'true'
with:
commit_message: 'chore(config): automatic conversion of application.yml to ors-config.yml'
11 changes: 10 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,20 @@ COPY --chown=ors:ors --from=tomcat /tmp/tomcat ${BASE_FOLDER}/tomcat
COPY --chown=ors:ors --from=build /ors-core/ors-api/target/ors.war ${BASE_FOLDER}/tomcat/webapps/ors.war
COPY --chown=ors:ors --from=build /ors-core/ors-api/src/main/resources/log4j-tomcat.properties ${BASE_FOLDER}/tomcat/conf/logging.properties
COPY --chown=ors:ors ./docker-entrypoint.sh ${BASE_FOLDER}/docker-entrypoint.sh
COPY --chown=ors:ors ./ors-api/ors-config.yml ${BASE_FOLDER}/tmp/ors-config.yml
COPY --chown=ors:ors ./ors-config.yml ${BASE_FOLDER}/tmp/ors-config.yml
COPY --chown=ors:ors ./$OSM_FILE ${BASE_FOLDER}/tmp/osm_file.pbf

USER ${UID}:${GID}

# Rewrite the ' source_file: ors-api/src/test/files/heidelberg.osm.gz' line in the config file to ' source_file: ${BASE_FOLDER}/ors-core/data/osm_file.pbf'
RUN sed -i "s| source_file: ors-api/src/test/files/heidelberg.osm.gz| source_file: ${BASE_FOLDER}/ors-core/data/osm_file.pbf|g" ${BASE_FOLDER}/tmp/ors-config.yml
# Rewrite the '# graphs_root_path: ./graphs' line in the config file to ' graphs_root_path: ${BASE_FOLDER}/ors-core/data/graphs'
RUN sed -i "s|# graphs_root_path: ./graphs| graphs_root_path: ${BASE_FOLDER}/ors-core/data/graphs|g" ${BASE_FOLDER}/tmp/ors-config.yml
# Rewrite the '# elevation:' line in the config file to ' elevation:'
RUN sed -i "s|# elevation:| elevation:|g" ${BASE_FOLDER}/tmp/ors-config.yml
# Rewrite the '# cache_path: ./elevation_cache' line in the config file to ' cache_path: ${BASE_FOLDER}/ors-core/data/elevation_cache'
RUN sed -i "s|# cache_path: ./elevation_cache| cache_path: ${BASE_FOLDER}/ors-core/data/elevation_cache|g" ${BASE_FOLDER}/tmp/ors-config.yml

ENV BUILD_GRAPHS="False"
ENV ORS_CONFIG_LOCATION=ors-conf/ors-config.yml

Expand Down
195 changes: 0 additions & 195 deletions ors-api/ors-config.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ public RouteProfileConfiguration[] getConvertedProfiles() {
if (profiles != null) {
for (Map.Entry<String, ProfileProperties> profileEntry : profiles.entrySet()) {
ProfileProperties profile = profileEntry.getValue();
if (!profile.isEnabled()) {
continue;
}
RouteProfileConfiguration convertedProfile = new RouteProfileConfiguration();
convertedProfile.setName(profileEntry.getKey());
convertedProfile.setEnabled(profile.enabled != null ? profile.enabled : profileDefault.isEnabled());
Expand Down
Loading
Loading