From 348457cb3e91744b96b9b6349def0ad61ee0f1da Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Tue, 8 Nov 2022 15:27:36 +0900 Subject: [PATCH 01/34] feat: update CHANGELOG.md --- CHANGELOG.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a52272c87..653e27e73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,66 @@ # Change Log + +## [v0.25.2-2022-11-08](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-11-08) + +### Added +- Add notification to slack [#452](https://github.com/codeforjapan/decidim-cfj/pull/452) +- Add task comment:remove_orphans [#454](https://github.com/codeforjapan/decidim-cfj/pull/454) +- Add comments for Decidim::ImageUploader in UPGRADE.md [#458](https://github.com/codeforjapan/decidim-cfj/pull/458) +- feat: add slack env [#459](https://github.com/codeforjapan/decidim-cfj/pull/459) +- feat: add print css [#460](https://github.com/codeforjapan/decidim-cfj/pull/460) + +### Changed +- refactor: change image upload size limit [#455](https://github.com/codeforjapan/decidim-cfj/pull/455) + + +### Fixed +- locale: fix term census [#456](https://github.com/codeforjapan/decidim-cfj/pull/456) +- locale: fix collaborative_draft [#457](https://github.com/codeforjapan/decidim-cfj/pull/457) + +## [v0.25.2-2022-10-25](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-10-25) + +### Added +- feat: add support for heic format [#438](https://github.com/codeforjapan/decidim-cfj/pull/438) +- Make frequncy of puma-worker-killer 60(sec) [#451](https://github.com/codeforjapan/decidim-cfj/pull/451) + +### Changed +- Update actions/checkout and actions/setup-node [#441](https://github.com/codeforjapan/decidim-cfj/pull/441) + +### Fixed +- Fix nginx.conf; add $proxy_port to Host header [#440](https://github.com/codeforjapan/decidim-cfj/pull/440) +- Fix/production nginx.conf [#442](https://github.com/codeforjapan/decidim-cfj/pull/442) +- hotfix: deployments nginx conf [#443](https://github.com/codeforjapan/decidim-cfj/pull/443) +- Refactor/some fix [#444](https://github.com/codeforjapan/decidim-cfj/pull/444) +- fix: user upload image error [#445](https://github.com/codeforjapan/decidim-cfj/pull/445) +- Fix #446; set max_complexity after initializers [#450](https://github.com/codeforjapan/decidim-cfj/pull/450) + + +## [v0.25.2-2022-09-29](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-09-29) + +### Added +- feat: add replace to null ParticipatoryProcess command [#423](https://github.com/codeforjapan/decidim-cfj/pull/423) +- feat: add replace to null decidim_proposals command [#436](https://github.com/codeforjapan/decidim-cfj/pull/436) + +### Changed +- Remove ProcessParticipatorySpacePrivateUserImportCsv [#428](https://github.com/codeforjapan/decidim-cfj/pull/428) +- Add some items in UPGRADE.md [#431](https://github.com/codeforjapan/decidim-cfj/pull/431) +- Remove _main_footer.html.erb patch file; already fixed in #138 [#435](https://github.com/codeforjapan/decidim-cfj/pull/435) + +### Fixed +- Revert #210; Fixed in v0.25.2 [#429](https://github.com/codeforjapan/decidim-cfj/pull/429) +- Fix paths in UPGRADE.md [#430](https://github.com/codeforjapan/decidim-cfj/pull/430) +- doc: Remove fixed(removed) files in UPGRADE.md [#432](https://github.com/codeforjapan/decidim-cfj/pull/432) + +## [v0.25.2-2022-09-16](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-09-16) + +### Added +- Set max_complexity of GraphQL::Schema [#426](https://github.com/codeforjapan/decidim-cfj/pull/426) + +## [v0.25.2-2022-09-15](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-09-15) + +### Added +- feat: add replace to null ParticipatoryProcess command [#423](https://github.com/codeforjapan/decidim-cfj/pull/423) + ## [v0.25.2-2022-09-09](https://github.com/codeforjapan/decidim-cfj/releases/tag/v0.25.2-2022-09-09) ### Added From 57a0013f82dd79ec184e3fba1763db3c31ad1aad Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 20:26:14 +0900 Subject: [PATCH 02/34] refactor: Move SlackChatMessenger to use in Decidim apps --- config/initializers/slack.rb | 1 + config/puma.rb | 13 ++----------- lib/slack_chat_messenger.rb | 12 ++++++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 lib/slack_chat_messenger.rb diff --git a/config/initializers/slack.rb b/config/initializers/slack.rb index 5ad79d56b..ddba99182 100644 --- a/config/initializers/slack.rb +++ b/config/initializers/slack.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "slack-ruby-client" +require_relative "../../lib/slack_chat_messenger" Slack.configure do |config| config.token = ENV["SLACK_API_TOKEN"] diff --git a/config/puma.rb b/config/puma.rb index 06022d09b..fa5f36b84 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative "../lib/slack_chat_messenger" + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match @@ -20,17 +22,6 @@ # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") -class SlackChatMessenger - def self.notify(channel:, message:) - unless channel && message - Rails.logger.error "Cannot send messages to slack!" - return - end - client = Slack::Web::Client.new - client.chat_postMessage(channel: channel, text: message, as_user: true) - end -end - before_fork do PumaWorkerKiller.config do |config| config.ram = 2048 diff --git a/lib/slack_chat_messenger.rb b/lib/slack_chat_messenger.rb new file mode 100644 index 000000000..c36d45f83 --- /dev/null +++ b/lib/slack_chat_messenger.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class SlackChatMessenger + def self.notify(channel:, message:) + unless channel && message + Rails.logger.error "Cannot send messages to slack!" + return + end + client = Slack::Web::Client.new + client.chat_postMessage(channel: channel, text: message, as_user: true) + end +end From 0f330cb2fa13cb21b4a7252652b07467019cf07c Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 20:42:04 +0900 Subject: [PATCH 03/34] Remove application.css --- app/packs/stylesheets/application.css | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 app/packs/stylesheets/application.css diff --git a/app/packs/stylesheets/application.css b/app/packs/stylesheets/application.css deleted file mode 100644 index c64fd7be5..000000000 --- a/app/packs/stylesheets/application.css +++ /dev/null @@ -1,16 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's - * vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS - * files in this directory. Styles in this file should be added after the last require_* statement. - * It is generally better to create a new file per style scope. - * - *= require decidim - *= require_tree . - *= require_self - */ From 887b717ea19301ab8143d7c4da23fe053cbd9ce9 Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 20:43:08 +0900 Subject: [PATCH 04/34] Move (S)CSS variable to _decidim-settings.scss --- app/packs/stylesheets/decidim.scss | 8 +------- app/packs/stylesheets/decidim/_decidim-settings.scss | 3 ++- app/packs/stylesheets/decidim/settings.scss | 7 +++++++ 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 app/packs/stylesheets/decidim/settings.scss diff --git a/app/packs/stylesheets/decidim.scss b/app/packs/stylesheets/decidim.scss index 67349523a..2c007833d 100644 --- a/app/packs/stylesheets/decidim.scss +++ b/app/packs/stylesheets/decidim.scss @@ -74,12 +74,6 @@ } } -$bgcolor: #fffffe; -$headline: #28abb9; -$menu: #2d6187; -$point-color: #ef4565; -$paragraph: #5f6c7b; - // overide existing styles .navbar { background: $menu; @@ -149,4 +143,4 @@ $paragraph: #5f6c7b; .menu li, .menu.horizontal li { white-space: nowrap; -} \ No newline at end of file +} diff --git a/app/packs/stylesheets/decidim/_decidim-settings.scss b/app/packs/stylesheets/decidim/_decidim-settings.scss index 924c102d2..939ff4111 100644 --- a/app/packs/stylesheets/decidim/_decidim-settings.scss +++ b/app/packs/stylesheets/decidim/_decidim-settings.scss @@ -5,4 +5,5 @@ // To override styles use decidim_application.scss // // By default this is empty. -@import "../decidim"; \ No newline at end of file +@import "./settings"; +@import "../decidim"; diff --git a/app/packs/stylesheets/decidim/settings.scss b/app/packs/stylesheets/decidim/settings.scss new file mode 100644 index 000000000..41db0d0e2 --- /dev/null +++ b/app/packs/stylesheets/decidim/settings.scss @@ -0,0 +1,7 @@ +// Override default settings(CSS variables) + +$bgcolor: #fffffe; +$headline: #28abb9; +$menu: #2d6187; +$point-color: #ef4565; +$paragraph: #5f6c7b; From e22339f2e4ddbabd6955e77f2967d8f00188a3fe Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 22:09:27 +0900 Subject: [PATCH 05/34] _decidim-settings should be used as variables --- app/packs/stylesheets/decidim/_decidim-settings.scss | 1 - app/packs/stylesheets/decidim/decidim_application.scss | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/packs/stylesheets/decidim/_decidim-settings.scss b/app/packs/stylesheets/decidim/_decidim-settings.scss index 939ff4111..243f6d3df 100644 --- a/app/packs/stylesheets/decidim/_decidim-settings.scss +++ b/app/packs/stylesheets/decidim/_decidim-settings.scss @@ -6,4 +6,3 @@ // // By default this is empty. @import "./settings"; -@import "../decidim"; diff --git a/app/packs/stylesheets/decidim/decidim_application.scss b/app/packs/stylesheets/decidim/decidim_application.scss index 950de0ee2..244688ea2 100644 --- a/app/packs/stylesheets/decidim/decidim_application.scss +++ b/app/packs/stylesheets/decidim/decidim_application.scss @@ -5,6 +5,7 @@ // To override CSS variables or Foundation settings use _decidim-settings.scss // // By default this is empty. +@import "../decidim"; @import "../buttons"; @import "../comment_content"; @import "../forms"; From de5e83d7509417c1515aef9edd4ed8ba22703551 Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 22:30:30 +0900 Subject: [PATCH 06/34] move scss files into app/packs/stylesheets/decidim/cfj/ --- app/packs/stylesheets/decidim/_decidim-settings.scss | 2 +- app/packs/stylesheets/{ => decidim/cfj}/buttons.scss | 0 .../{ => decidim/cfj}/comment_content.scss | 0 app/packs/stylesheets/{ => decidim/cfj}/decidim.scss | 0 app/packs/stylesheets/{ => decidim/cfj}/forms.scss | 0 .../stylesheets/{ => decidim/cfj}/media_print.scss | 0 app/packs/stylesheets/{ => decidim/cfj}/search.scss | 0 .../stylesheets/decidim/{ => cfj}/settings.scss | 0 .../stylesheets/decidim/decidim_application.scss | 12 ++++++------ 9 files changed, 7 insertions(+), 7 deletions(-) rename app/packs/stylesheets/{ => decidim/cfj}/buttons.scss (100%) rename app/packs/stylesheets/{ => decidim/cfj}/comment_content.scss (100%) rename app/packs/stylesheets/{ => decidim/cfj}/decidim.scss (100%) rename app/packs/stylesheets/{ => decidim/cfj}/forms.scss (100%) rename app/packs/stylesheets/{ => decidim/cfj}/media_print.scss (100%) rename app/packs/stylesheets/{ => decidim/cfj}/search.scss (100%) rename app/packs/stylesheets/decidim/{ => cfj}/settings.scss (100%) diff --git a/app/packs/stylesheets/decidim/_decidim-settings.scss b/app/packs/stylesheets/decidim/_decidim-settings.scss index 243f6d3df..b8d634ae8 100644 --- a/app/packs/stylesheets/decidim/_decidim-settings.scss +++ b/app/packs/stylesheets/decidim/_decidim-settings.scss @@ -5,4 +5,4 @@ // To override styles use decidim_application.scss // // By default this is empty. -@import "./settings"; +@import "./cfj/settings"; diff --git a/app/packs/stylesheets/buttons.scss b/app/packs/stylesheets/decidim/cfj/buttons.scss similarity index 100% rename from app/packs/stylesheets/buttons.scss rename to app/packs/stylesheets/decidim/cfj/buttons.scss diff --git a/app/packs/stylesheets/comment_content.scss b/app/packs/stylesheets/decidim/cfj/comment_content.scss similarity index 100% rename from app/packs/stylesheets/comment_content.scss rename to app/packs/stylesheets/decidim/cfj/comment_content.scss diff --git a/app/packs/stylesheets/decidim.scss b/app/packs/stylesheets/decidim/cfj/decidim.scss similarity index 100% rename from app/packs/stylesheets/decidim.scss rename to app/packs/stylesheets/decidim/cfj/decidim.scss diff --git a/app/packs/stylesheets/forms.scss b/app/packs/stylesheets/decidim/cfj/forms.scss similarity index 100% rename from app/packs/stylesheets/forms.scss rename to app/packs/stylesheets/decidim/cfj/forms.scss diff --git a/app/packs/stylesheets/media_print.scss b/app/packs/stylesheets/decidim/cfj/media_print.scss similarity index 100% rename from app/packs/stylesheets/media_print.scss rename to app/packs/stylesheets/decidim/cfj/media_print.scss diff --git a/app/packs/stylesheets/search.scss b/app/packs/stylesheets/decidim/cfj/search.scss similarity index 100% rename from app/packs/stylesheets/search.scss rename to app/packs/stylesheets/decidim/cfj/search.scss diff --git a/app/packs/stylesheets/decidim/settings.scss b/app/packs/stylesheets/decidim/cfj/settings.scss similarity index 100% rename from app/packs/stylesheets/decidim/settings.scss rename to app/packs/stylesheets/decidim/cfj/settings.scss diff --git a/app/packs/stylesheets/decidim/decidim_application.scss b/app/packs/stylesheets/decidim/decidim_application.scss index 244688ea2..b05be4081 100644 --- a/app/packs/stylesheets/decidim/decidim_application.scss +++ b/app/packs/stylesheets/decidim/decidim_application.scss @@ -5,9 +5,9 @@ // To override CSS variables or Foundation settings use _decidim-settings.scss // // By default this is empty. -@import "../decidim"; -@import "../buttons"; -@import "../comment_content"; -@import "../forms"; -@import "../search"; -@import "../media_print"; +@import "./cfj/decidim"; +@import "./cfj/buttons"; +@import "./cfj/comment_content"; +@import "./cfj/forms"; +@import "./cfj/search"; +@import "./cfj/media_print"; From 607edf76dc3ab2714c3b97f90ac2fed60646f28b Mon Sep 17 00:00:00 2001 From: takahashim Date: Thu, 17 Nov 2022 23:39:28 +0900 Subject: [PATCH 07/34] Remove `.keep` files --- app/packs/src/decidim/.keep | 0 app/packs/stylesheets/decidim/.keep | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/packs/src/decidim/.keep delete mode 100644 app/packs/stylesheets/decidim/.keep diff --git a/app/packs/src/decidim/.keep b/app/packs/src/decidim/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/packs/stylesheets/decidim/.keep b/app/packs/stylesheets/decidim/.keep deleted file mode 100644 index e69de29bb..000000000 From 49bd58af3682da50c16d79a87ffdfb4f2b1caa7d Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 19 Nov 2022 00:01:34 +0900 Subject: [PATCH 08/34] Remove src/application.js Use entrypoints/application.js in current Decidim --- app/packs/entrypoints/application.js | 4 ++-- app/packs/src/application.js | 21 --------------------- 2 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 app/packs/src/application.js diff --git a/app/packs/entrypoints/application.js b/app/packs/entrypoints/application.js index 2b1c84145..5e3eee1f3 100644 --- a/app/packs/entrypoints/application.js +++ b/app/packs/entrypoints/application.js @@ -15,6 +15,6 @@ // const imagePath = (name) => images(name, true) // Activate Active Storage -// import * as ActiveStorage from "@rails/activestorage" -// ActiveStorage.start() +import * as ActiveStorage from "@rails/activestorage" +ActiveStorage.start() import "src/decidim/decidim_awesome/awesome_admin" diff --git a/app/packs/src/application.js b/app/packs/src/application.js deleted file mode 100644 index 89f5c61f3..000000000 --- a/app/packs/src/application.js +++ /dev/null @@ -1,21 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's -// vendor/assets/javascripts directory can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. JavaScript code in this file should be added after the last require_* statement. -// -// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details -// about supported directives. -// -import "jquery" -import Rails from "@rails/ujs" -import * as ActiveStorage from "@rails/activestorage" -import "channels" - -Rails.start() -ActiveStorage.start() - -require('decidim') From 14c4d296522fe5f5404b1378ae571fd9705d034e Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 19 Nov 2022 01:20:25 +0900 Subject: [PATCH 09/34] refactor: move CSS from editor.js --- .../decidim/decidim_awesome/editors/editor.js | 60 ------------------- .../decidim/cfj/ql_html_editor.scss | 53 ++++++++++++++++ 2 files changed, 53 insertions(+), 60 deletions(-) create mode 100644 app/packs/stylesheets/decidim/cfj/ql_html_editor.scss diff --git a/app/packs/src/decidim/decidim_awesome/editors/editor.js b/app/packs/src/decidim/decidim_awesome/editors/editor.js index f6c644712..063ad328a 100644 --- a/app/packs/src/decidim/decidim_awesome/editors/editor.js +++ b/app/packs/src/decidim/decidim_awesome/editors/editor.js @@ -40,66 +40,6 @@ export function destroyQuillEditor(container) { export function createQuillEditor(container) { // decidim-cfj custom start - function __createCSS() { - var css = document.createElement("style") - css.type = "text/css" - css.innerText = ` -.ql-html-overlayContainer { - background: #0000007d; - position: fixed; - top: 0; - left: 0; - right: 0; - bottom: 0; - z-index: 9999; -} - -.ql-html-popupContainer { - background: #ddd; - position: absolute; - top: 5%; - left: 5%; - right: 5%; - bottom: 5%; - border-radius: 10px; -} - -.ql-html-textContainer { - position: relative; - width: calc(100% - 40px); - height: calc(100% - 40px); - padding: 20px; -} - -.ql-html-textArea { - background: #fff; - position: absolute; - left: 15px; - width: calc(100% - 45px); - height: calc(100% - 116px); -} - -.ql-html-buttonCancel { - margin-right: 20px; -} - -.ql-html-popupTitle { - margin: 0; - display: block; -} - -.ql-html-buttonGroup { - position: absolute; - bottom: 20px; - transform: scale(1.5); - left: calc(50% - 60px); -} - `; - document.head.appendChild(css); - } - __createCSS(); - - function $create(elName) { return document.createElement(elName); } diff --git a/app/packs/stylesheets/decidim/cfj/ql_html_editor.scss b/app/packs/stylesheets/decidim/cfj/ql_html_editor.scss new file mode 100644 index 000000000..84eb531f5 --- /dev/null +++ b/app/packs/stylesheets/decidim/cfj/ql_html_editor.scss @@ -0,0 +1,53 @@ +/* + * for Quill HTML Editor + */ +.ql-html-overlayContainer { + background: #0000007d; + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 9999; +} + +.ql-html-popupContainer { + background: #ddd; + position: absolute; + top: 5%; + left: 5%; + right: 5%; + bottom: 5%; + border-radius: 10px; +} + +.ql-html-textContainer { + position: relative; + width: calc(100% - 40px); + height: calc(100% - 40px); + padding: 20px; +} + +.ql-html-textArea { + background: #fff; + position: absolute; + left: 15px; + width: calc(100% - 45px); + height: calc(100% - 116px); +} + +.ql-html-buttonCancel { + margin-right: 20px; +} + +.ql-html-popupTitle { + margin: 0; + display: block; +} + +.ql-html-buttonGroup { + position: absolute; + bottom: 20px; + transform: scale(1.5); + left: calc(50% - 60px); +} From 2033c12d487b0385d6ce8b17746916cebc3f8240 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 19 Nov 2022 01:41:31 +0900 Subject: [PATCH 10/34] Comment out ActiveStorage in JS --- app/packs/entrypoints/application.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/packs/entrypoints/application.js b/app/packs/entrypoints/application.js index 5e3eee1f3..2b1c84145 100644 --- a/app/packs/entrypoints/application.js +++ b/app/packs/entrypoints/application.js @@ -15,6 +15,6 @@ // const imagePath = (name) => images(name, true) // Activate Active Storage -import * as ActiveStorage from "@rails/activestorage" -ActiveStorage.start() +// import * as ActiveStorage from "@rails/activestorage" +// ActiveStorage.start() import "src/decidim/decidim_awesome/awesome_admin" From 65f8bd53c957b031ee4e1c4d1e85dad5bbcf62cb Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:27:43 +0900 Subject: [PATCH 11/34] refactor: fix warning --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c123319c2..04335f2ea 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,8 +36,8 @@ jobs: - name: Output App Env id: output-app-env run: | - echo "::set-output name=image-tag::${IMAGE_TAG_PREFIX}-${GITHUB_SHA::8}" - echo "::set-output name=eb-environment-name::${EB_ENVIRONMENT_NAME}" + echo "image-tag::${IMAGE_TAG_PREFIX}-${GITHUB_SHA=8}" >> $GITHUB_OUTPUT + echo "eb-environment-name=${EB_ENVIRONMENT_NAME}" >> $GITHUB_OUTPUT build: runs-on: ubuntu-latest @@ -48,7 +48,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -80,7 +80,7 @@ jobs: - uses: actions/checkout@v3 - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From cc4cc81545df051af725628b8a28fc732a0db83c Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 21 Nov 2022 19:52:37 +0900 Subject: [PATCH 12/34] Add into decidim_application.scss --- app/packs/stylesheets/decidim/decidim_application.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/packs/stylesheets/decidim/decidim_application.scss b/app/packs/stylesheets/decidim/decidim_application.scss index b05be4081..9b6e96153 100644 --- a/app/packs/stylesheets/decidim/decidim_application.scss +++ b/app/packs/stylesheets/decidim/decidim_application.scss @@ -11,3 +11,4 @@ @import "./cfj/forms"; @import "./cfj/search"; @import "./cfj/media_print"; +@import "./cfj/ql_html_editor"; From 027d21cdd876bd8523a13df89c7af81c8d7dd3bb Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Thu, 24 Nov 2022 16:09:14 +0900 Subject: [PATCH 13/34] feat: add cdk deploy --- .github/workflows/deploy.yml | 37 +++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 04335f2ea..cc456d53d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,10 +8,17 @@ on: tags: - 'v*' +env: + AWS_ROLE_ARN: arn:aws:iam::887442827229:role/GithubActions_decidim-cfj-cdk-deploy + jobs: create-app-env: runs-on: ubuntu-latest timeout-minutes: 60 + permissions: + actions: write + contents: read + id-token: write outputs: image-tag: ${{ steps.output-app-env.outputs.image-tag }} eb-environment-name: ${{ steps.output-app-env.outputs.eb-environment-name }} @@ -111,15 +118,27 @@ jobs: - name: Install awsebcli run: pip install -U awsebcli - - name: Deploy to Elastic Beanstalk + - name: Checkout decidim-cfj cdk + uses: actions/checkout@v3 + with: + repository: codeforjapan/decidim-cfj-cdk + path: ./ + + - name: aws switch role + uses: aws-actions/configure-aws-credentials@v1 + with: + role-to-assume: ${{ env.AWS_ROLE_ARN }} + aws-region: ap-northeast-1 + + - name: cdk deploy + uses: youyo/aws-cdk-github-actions@v2 + with: + cdk_subcommand: 'deploy' + cdk_version: '2.50.0' + actions_comment: true + cdk_args: '--context stage=$EB_ENVIRONMENT_NAME --context tag:$IMAGE_TAG --require-approval never' env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + AWS_DEFAULT_REGION: 'ap-northeast-1' EB_ENVIRONMENT_NAME: ${{ needs.create-app-env.outputs.eb-environment-name }} IMAGE_TAG: ${{ needs.create-app-env.outputs.image-tag }} - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }} - run: | - cd deployments - cp ${EB_ENVIRONMENT_NAME}/*.config .ebextensions/ - sed -i -e "s|{RepositoryName}|$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG|g" docker-compose.yml - sed -i -e "s|{EBEnvironment}|$EB_ENVIRONMENT_NAME|g" docker-compose.yml - eb deploy ${EB_ENVIRONMENT_NAME} --timeout=20 --process From 2b06cc26a81b69105325fa15f0f0df7fdf38a3a2 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Thu, 24 Nov 2022 16:17:51 +0900 Subject: [PATCH 14/34] feat: add working_dir --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cc456d53d..6124c4c99 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -137,6 +137,7 @@ jobs: cdk_version: '2.50.0' actions_comment: true cdk_args: '--context stage=$EB_ENVIRONMENT_NAME --context tag:$IMAGE_TAG --require-approval never' + working_dir: 'decidim-cfj-cdk' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} AWS_DEFAULT_REGION: 'ap-northeast-1' From d2b1b71fbeab4d3a20763479ff056a77e9dbc516 Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 28 Nov 2022 19:37:32 +0900 Subject: [PATCH 15/34] Fix old message for endorsement button --- config/locales/ja.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 20dd3f954..62d30788b 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -100,8 +100,6 @@ ja: authorizations: new: connect_your_account_html: "%{organization} にログインしてアカウントに接続します" - endorsement_buttons_cell: - already_endorsed: 支持済み errors: not_found: content_doesnt_exist: このアドレスは正しくないか削除されています。 From 085a01969f50cc3faacc83b7ed190a389bdbba1b Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 29 Nov 2022 00:10:17 +0900 Subject: [PATCH 16/34] Copy admin/appplication.scss from decidim-admin --- .../decidim/admin/application.scss | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/packs/stylesheets/decidim/admin/application.scss diff --git a/app/packs/stylesheets/decidim/admin/application.scss b/app/packs/stylesheets/decidim/admin/application.scss new file mode 100644 index 000000000..d62f61b09 --- /dev/null +++ b/app/packs/stylesheets/decidim/admin/application.scss @@ -0,0 +1,22 @@ +@import "stylesheets/decidim/admin/decidim"; +@import "stylesheets/decidim/admin/extra/action-icon"; +@import "stylesheets/decidim/admin/extra/block_user"; +@import "stylesheets/decidim/admin/extra/cards"; +@import "stylesheets/decidim/admin/extra/categories"; +@import "stylesheets/decidim/admin/extra/dropdown_inverted"; +@import "stylesheets/decidim/admin/extra/editor"; +@import "stylesheets/decidim/admin/extra/email_preview"; +@import "stylesheets/decidim/admin/extra/label-required"; +@import "stylesheets/decidim/admin/extra/login"; +@import "stylesheets/decidim/admin/extra/logs"; +@import "stylesheets/decidim/admin/extra/newsletter-templates-gallery"; +@import "stylesheets/decidim/admin/extra/organization-appearance"; +@import "stylesheets/decidim/admin/extra/quill"; +@import "stylesheets/decidim/admin/extra/select_multiple"; +@import "stylesheets/decidim/admin/extra/show_email"; +@import "stylesheets/decidim/admin/extra/sort"; +@import "stylesheets/decidim/admin/extra/title_bar"; + +// This imports all the Decidim module stylesheet imports registered at +// `config/assets.rb` of the module for the "admin" group. +@import "!decidim-style-imports[admin]"; From 5b537c408efa8747bc489b8d8b15c4b540e690ec Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 29 Nov 2022 00:10:41 +0900 Subject: [PATCH 17/34] Add cfj/ql_html_editor.scss into admin/application.scss --- app/packs/stylesheets/decidim/admin/application.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/packs/stylesheets/decidim/admin/application.scss b/app/packs/stylesheets/decidim/admin/application.scss index d62f61b09..afd6eea29 100644 --- a/app/packs/stylesheets/decidim/admin/application.scss +++ b/app/packs/stylesheets/decidim/admin/application.scss @@ -17,6 +17,8 @@ @import "stylesheets/decidim/admin/extra/sort"; @import "stylesheets/decidim/admin/extra/title_bar"; +@import "stylesheets/decidim/cfj/ql_html_editor"; + // This imports all the Decidim module stylesheet imports registered at // `config/assets.rb` of the module for the "admin" group. @import "!decidim-style-imports[admin]"; From e042f4dcce085de750c42b6809722f5d69a84470 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Fri, 2 Dec 2022 16:11:17 +0900 Subject: [PATCH 18/34] fix: some bug --- .github/workflows/deploy.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6124c4c99..e81fec34a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy to Elastic Beanstalk +name: Deploy to decidim-cfj cdk on: push: @@ -43,7 +43,7 @@ jobs: - name: Output App Env id: output-app-env run: | - echo "image-tag::${IMAGE_TAG_PREFIX}-${GITHUB_SHA=8}" >> $GITHUB_OUTPUT + echo "image-tag=${IMAGE_TAG_PREFIX}-${GITHUB_SHA::8}" >> $GITHUB_OUTPUT echo "eb-environment-name=${EB_ENVIRONMENT_NAME}" >> $GITHUB_OUTPUT build: @@ -79,6 +79,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 1800 if: endsWith(github.ref, 'heads/develop') || contains(github.ref, 'tags/v') + permissions: + actions: write + contents: read + id-token: write needs: - create-app-env - build @@ -89,8 +93,7 @@ jobs: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + role-to-assume: ${{ env.AWS_ROLE_ARN }} aws-region: ap-northeast-1 - name: Login to Amazon ECR @@ -122,13 +125,7 @@ jobs: uses: actions/checkout@v3 with: repository: codeforjapan/decidim-cfj-cdk - path: ./ - - - name: aws switch role - uses: aws-actions/configure-aws-credentials@v1 - with: - role-to-assume: ${{ env.AWS_ROLE_ARN }} - aws-region: ap-northeast-1 + path: decidim-cfj-cdk - name: cdk deploy uses: youyo/aws-cdk-github-actions@v2 @@ -136,7 +133,7 @@ jobs: cdk_subcommand: 'deploy' cdk_version: '2.50.0' actions_comment: true - cdk_args: '--context stage=$EB_ENVIRONMENT_NAME --context tag:$IMAGE_TAG --require-approval never' + cdk_args: '--context stage=$EB_ENVIRONMENT_NAME --context tag=$IMAGE_TAG --require-approval never' working_dir: 'decidim-cfj-cdk' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From f36c19593c74e83e0591dba3b4d607ab6860ea0a Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Fri, 2 Dec 2022 17:21:55 +0900 Subject: [PATCH 19/34] refactor: deploy change command --- .github/workflows/deploy.yml | 51 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e81fec34a..c419fb88f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -50,6 +50,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 1200 needs: create-app-env + permissions: + actions: write + contents: read + id-token: write steps: - uses: actions/checkout@v3 @@ -57,8 +61,7 @@ jobs: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + role-to-assume: ${{ env.AWS_ROLE_ARN }} aws-region: ap-northeast-1 - name: Login to Amazon ECR @@ -114,29 +117,43 @@ jobs: exit 1 fi - - uses: actions/setup-python@master - with: - python-version: "3.7" - - - name: Install awsebcli - run: pip install -U awsebcli - - name: Checkout decidim-cfj cdk uses: actions/checkout@v3 with: repository: codeforjapan/decidim-cfj-cdk path: decidim-cfj-cdk - - name: cdk deploy - uses: youyo/aws-cdk-github-actions@v2 + - name: Setup Node + uses: actions/setup-node@v1 with: - cdk_subcommand: 'deploy' - cdk_version: '2.50.0' - actions_comment: true - cdk_args: '--context stage=$EB_ENVIRONMENT_NAME --context tag=$IMAGE_TAG --require-approval never' - working_dir: 'decidim-cfj-cdk' + node-version: '16' + + - name: Cache node modules + id: cache-npm + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Install dependencies + run: npm install + working-directory: decidim-cfj-cdk + + - name: Install dependencies + run: npm install -g aws-cdk + working-directory: decidim-cfj-cdk + + - name: cdk deploy + run: cdk -c stage=$EB_ENVIRONMENT_NAME -c tag=$IMAGE_TAG deploy --all --require-approval never + working-directory: decidim-cfj-cdk env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} AWS_DEFAULT_REGION: 'ap-northeast-1' EB_ENVIRONMENT_NAME: ${{ needs.create-app-env.outputs.eb-environment-name }} IMAGE_TAG: ${{ needs.create-app-env.outputs.image-tag }} From 72cfb206603668000a7376fedc5eb46104b909b0 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Fri, 2 Dec 2022 19:15:52 +0900 Subject: [PATCH 20/34] feat: add geo cording osm --- config/initializers/decidim.rb | 22 ++++++++++++++++++---- config/secrets.yml | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index b81ef1ff2..9f64079d5 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -36,10 +36,24 @@ # config.force_ssl = true # Geocoder configuration - # config.geocoder = { - # static_map_url: "https://image.maps.ls.hereapi.com/mia/1.6/mapview", - # here_api_key: Rails.application.secrets.geocoder[:here_api_key] - # } + config.maps = { + provider: :osm, + api_key: Rails.application.secrets.maps[:api_key], + dynamic: { + tile_layer: { + url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + api_key: true, + attribution: %( + © OpenStreetMap contributors + ).strip + # Translatable attribution: + # attribution: -> { I18n.t("tile_layer_attribution") } + } + }, + # static: { url: "https://staticmap.example.org/" }, # optional + geocoding: { host: "www.openstreetmap.org/", use_https: true }, + autocomplete: { url: "https://nominatim.openstreetmap.org/search"} + } # Custom resource reference generator method. Check the docs for more info. # config.reference_generator = lambda do |resource, component| diff --git a/config/secrets.yml b/config/secrets.yml index b9fce8d10..067423a02 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -32,6 +32,8 @@ default: &default client_secret: <%= ENV["OMNIAUTH_LINE_LOGIN_CHANNEL_SECRET"] %> geocoder: here_api_key: <%= ENV["GEOCODER_API_KEY"] %> + maps: + api_key: <%= ENV["MAPS_API_KEY"] %> etherpad: server: <%= ENV["ETHERPAD_SERVER"] %> api_key: <%= ENV["ETHERPAD_API_KEY"] %> From 0f166592f0c2efda0244443105f176efb3121040 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Fri, 2 Dec 2022 19:21:59 +0900 Subject: [PATCH 21/34] fix: lint --- config/initializers/decidim.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index 9f64079d5..2b266de61 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -52,7 +52,7 @@ }, # static: { url: "https://staticmap.example.org/" }, # optional geocoding: { host: "www.openstreetmap.org/", use_https: true }, - autocomplete: { url: "https://nominatim.openstreetmap.org/search"} + autocomplete: { url: "https://nominatim.openstreetmap.org/search" } } # Custom resource reference generator method. Check the docs for more info. From f661665397e0327e05fe11c46b1f6b6a9ce2967c Mon Sep 17 00:00:00 2001 From: takahashim Date: Sat, 3 Dec 2022 00:55:01 +0900 Subject: [PATCH 22/34] Fix configuration of geocoding --- config/initializers/decidim.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index 2b266de61..d0c764180 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -51,8 +51,8 @@ } }, # static: { url: "https://staticmap.example.org/" }, # optional - geocoding: { host: "www.openstreetmap.org/", use_https: true }, - autocomplete: { url: "https://nominatim.openstreetmap.org/search" } + geocoding: { host: "nominatim.openstreetmap.org", use_https: true } + # autocomplete: { url: "https://nominatim.openstreetmap.org/search" } } # Custom resource reference generator method. Check the docs for more info. From 427413e39c4c9678df6c7c62eb2e2552e5f60290 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Mon, 5 Dec 2022 14:40:24 +0900 Subject: [PATCH 23/34] refactor: apply this branch deploy --- .github/workflows/deploy.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c419fb88f..9e0658ddd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,6 +5,7 @@ on: branches: - develop - master + - feat/update-ci tags: - 'v*' @@ -28,7 +29,7 @@ jobs: - name: Set env to staging id: set-env-staging - if: endsWith(github.ref, 'heads/develop') + if: endsWith(github.ref, 'heads/develop') || endsWith(github.ref, 'heads/feat/update-ci') run: | echo "IMAGE_TAG_PREFIX=staging" >> $GITHUB_ENV echo "EB_ENVIRONMENT_NAME=staging" >> $GITHUB_ENV @@ -69,7 +70,7 @@ jobs: uses: aws-actions/amazon-ecr-login@v1 - name: Build, tag, and push image to Amazon ECR - if: endsWith(github.ref, 'heads/master') || endsWith(github.ref, 'heads/develop') + if: endsWith(github.ref, 'heads/master') || endsWith(github.ref, 'heads/develop') || endsWith(github.ref, 'heads/feat/update-ci') env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }} @@ -81,7 +82,7 @@ jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 1800 - if: endsWith(github.ref, 'heads/develop') || contains(github.ref, 'tags/v') + if: endsWith(github.ref, 'heads/develop') || contains(github.ref, 'tags/v') || endsWith(github.ref, 'heads/feat/update-ci') permissions: actions: write contents: read From 9bb12a908b8030a27c3e905e4d68c5974fecf42f Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Mon, 5 Dec 2022 16:08:13 +0900 Subject: [PATCH 24/34] refactor: rename --- .github/workflows/deploy.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9e0658ddd..23a0788c7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,11 +1,10 @@ -name: Deploy to decidim-cfj cdk +name: Deploy to ecs on: push: branches: - develop - master - - feat/update-ci tags: - 'v*' @@ -29,7 +28,7 @@ jobs: - name: Set env to staging id: set-env-staging - if: endsWith(github.ref, 'heads/develop') || endsWith(github.ref, 'heads/feat/update-ci') + if: endsWith(github.ref, 'heads/develop') run: | echo "IMAGE_TAG_PREFIX=staging" >> $GITHUB_ENV echo "EB_ENVIRONMENT_NAME=staging" >> $GITHUB_ENV @@ -70,7 +69,7 @@ jobs: uses: aws-actions/amazon-ecr-login@v1 - name: Build, tag, and push image to Amazon ECR - if: endsWith(github.ref, 'heads/master') || endsWith(github.ref, 'heads/develop') || endsWith(github.ref, 'heads/feat/update-ci') + if: endsWith(github.ref, 'heads/master') || endsWith(github.ref, 'heads/develop') env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }} @@ -82,7 +81,7 @@ jobs: deploy: runs-on: ubuntu-latest timeout-minutes: 1800 - if: endsWith(github.ref, 'heads/develop') || contains(github.ref, 'tags/v') || endsWith(github.ref, 'heads/feat/update-ci') + if: endsWith(github.ref, 'heads/develop') || contains(github.ref, 'tags/v') permissions: actions: write contents: read From 573bb91dd969e31d6c698494a3d261a3897bf7e4 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:40:01 +0900 Subject: [PATCH 25/34] refactor: deploy actions --- .github/workflows/deploy.yml | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 23a0788c7..5feed8542 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -58,6 +58,17 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1-node16 with: @@ -69,14 +80,19 @@ jobs: uses: aws-actions/amazon-ecr-login@v1 - name: Build, tag, and push image to Amazon ECR + uses: docker/build-push-action@v2 if: endsWith(github.ref, 'heads/master') || endsWith(github.ref, 'heads/develop') - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPO_NAME }} - IMAGE_TAG: ${{ needs.create-app-env.outputs.image-tag }} + id: build-image + with: + push: true + tags: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.AWS_ECR_REPO_NAME }}:${{ needs.create-app-env.outputs.image-tag }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache deploy: runs-on: ubuntu-latest From 40f7ad2b1146c78958e509cbc6d17bcaa6ead02b Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:47:20 +0900 Subject: [PATCH 26/34] refactor: cache rails packer compile --- .github/workflows/rails-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rails-test.yml b/.github/workflows/rails-test.yml index 5f7792e0e..2b88214dd 100644 --- a/.github/workflows/rails-test.yml +++ b/.github/workflows/rails-test.yml @@ -105,6 +105,7 @@ jobs: public/packs public/assets tmp/cache/assets + public/packs-test key: asset-precompile-cache-${{ hashFiles('ASSETS_VERSION') }} restore-keys: | asset-precompile-cache-${{ hashFiles('ASSETS_VERSION') }} From b92a31078210896b03c2a84076c7402ae6575953 Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 5 Dec 2022 22:39:05 +0900 Subject: [PATCH 27/34] Add original StaticMap Generator based on mapstatic --- config/initializers/decidim.rb | 7 +- .../map/provider/static_map/cfj_osm.rb | 61 +++++++ .../provider/static_map/cfj_osm/conversion.rb | 35 ++++ .../map/provider/static_map/cfj_osm/map.rb | 161 ++++++++++++++++++ .../map/provider/static_map/cfj_osm/tile.rb | 19 +++ .../static_map/cfj_osm/tile_source.rb | 52 ++++++ 6 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 lib/decidim/map/provider/static_map/cfj_osm.rb create mode 100644 lib/decidim/map/provider/static_map/cfj_osm/conversion.rb create mode 100644 lib/decidim/map/provider/static_map/cfj_osm/map.rb create mode 100644 lib/decidim/map/provider/static_map/cfj_osm/tile.rb create mode 100644 lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index d0c764180..b602cbcd0 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -50,7 +50,10 @@ # attribution: -> { I18n.t("tile_layer_attribution") } } }, - # static: { url: "https://staticmap.example.org/" }, # optional + static: { + provider: :cfj_osm, + url: 'http://www.openstreetmap.org/', + }, # use StaticMap::CfjOsm geocoding: { host: "nominatim.openstreetmap.org", use_https: true } # autocomplete: { url: "https://nominatim.openstreetmap.org/search" } } @@ -243,6 +246,8 @@ # config.machine_translation_service = "MyTranslationService" end +require "decidim/map/provider/static_map/cfj_osm" + Rails.application.config.i18n.available_locales = Decidim.available_locales Rails.application.config.i18n.default_locale = Decidim.default_locale diff --git a/lib/decidim/map/provider/static_map/cfj_osm.rb b/lib/decidim/map/provider/static_map/cfj_osm.rb new file mode 100644 index 000000000..1759527df --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require_relative 'cfj_osm/conversion' +require_relative 'cfj_osm/tile' +require_relative 'cfj_osm/tile_source' +require_relative 'cfj_osm/map' + +module Decidim + module Map + module Provider + module StaticMap + # The static map utility class based on Osm + class CfjOsm < ::Decidim::Map::StaticMap + def image_data(latitude:, longitude:, options: {}) + + zoom = options[:zoom] || 15 + width = options[:width] || 120 + height = options[:height] || 120 + + Rails.logger.info("######################image_data###############") + Rails.logger.info([latitude, longitude, zoom, width, height]) + + map = ::Decidim::Map::Provider::StaticMap::CfjOsm::Map.new( + zoom: zoom, + lat: latitude, + lng: longitude, + width: width, + height: height, + provider: 'http://tile.openstreetmap.jp/{z}/{x}/{y}.png', + organization: organization + ) + + Dir.mktmpdir do |dir| + tmpfile = File.join(dir, "map.png") + map.render_map(tmpfile) + + return File.binread(tmpfile) + end + end + + # @See Decidim::Map::StaticMap#url_params + def url_params(latitude:, longitude:, options: {}) + # This is the format used by osm-static-maps which is not an + # official OSM product but it should be rather easy to setup. For + # further information, see: + # https://github.com/jperelli/osm-static-maps + { + geojson: { + type: "Point", + coordinates: [longitude, latitude] + }.to_json, + zoom: options[:zoom] || 15, + width: options[:width] || 120, + height: options[:height] || 120 + } + end + end + end + end + end +end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb b/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb new file mode 100644 index 000000000..30b1a8ed3 --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb @@ -0,0 +1,35 @@ +module Decidim + module Map + module Provider + module StaticMap + class CfjOsm < ::Decidim::Map::StaticMap + + # Math Converter + class Conversion + def self.lng_to_x(lng, zoom) + n = 2 ** zoom + ((lng.to_f + 180) / 360) * n + end + + def self.x_to_lng(x, zoom) + n = 2.0 ** zoom + lon_deg = x / n * 360.0 - 180.0 + end + + def self.lat_to_y(lat, zoom) + n = 2 ** zoom + lat_rad = (lat / 180) * Math::PI + (1 - Math.log( Math.tan(lat_rad) + (1 / Math.cos(lat_rad)) ) / Math::PI) / 2 * n + end + + def self.y_to_lat(y, zoom) + n = 2.0 ** zoom + lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * y / n))) + lat_deg = lat_rad / (Math::PI / 180.0) + end + end + end + end + end + end +end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb new file mode 100644 index 000000000..e3e0e7d1f --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -0,0 +1,161 @@ +module Decidim + module Map + module Provider + module StaticMap + class CfjOsm < ::Decidim::Map::StaticMap + + # static map generator (cf. https://github.com/crofty/mapstatic) + class Map + TILE_SIZE = 256 + + attr_reader :zoom, :lat, :lng, :width, :height + attr_accessor :tile_source + + def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) + @lat = lat.to_f + @lng = lng.to_f + @width = width.to_f + @height = height.to_f + @zoom = zoom.to_i + @tile_source = TileSource.new(provider, organization) + end + + def width + @width ||= begin + left, bottom, right, top = bounding_box_in_tiles + (right - left) * TILE_SIZE + end + end + + def height + @height ||= begin + left, bottom, right, top = bounding_box_in_tiles + (bottom - top) * TILE_SIZE + end + end + + def to_image + base_image = create_uncropped_image + base_image = fill_image_with_tiles(base_image) + crop_to_size base_image + base_image + end + + def render_map(filename) + to_image.write filename + end + + def metadata + { + :bbox => bounding_box.join(','), + :width => width.to_i, + :height => height.to_i, + :zoom => zoom, + :number_of_tiles => required_tiles.length, + } + end + + private + + def x_tile_space + Conversion.lng_to_x(lng, zoom) + end + + def y_tile_space + Conversion.lat_to_y(lat, zoom) + end + + def width_tile_space + width / TILE_SIZE + end + + def height_tile_space + height / TILE_SIZE + end + + def bounding_box + @bounding_box ||= begin + left = Conversion.x_to_lng( x_tile_space - (width_tile_space / 2), zoom) + right = Conversion.x_to_lng( x_tile_space + ( width_tile_space / 2 ), zoom) + top = Conversion.y_to_lat( y_tile_space - ( height_tile_space / 2 ), zoom) + bottom = Conversion.y_to_lat( y_tile_space + ( height_tile_space / 2 ), zoom) + + [ left, bottom, right, top ] + end + end + + def bounding_box_in_tiles + left, bottom, right, top = bounding_box + [ + Conversion.lng_to_x(left, zoom), + Conversion.lat_to_y(bottom, zoom), + Conversion.lng_to_x(right, zoom), + Conversion.lat_to_y(top, zoom) + ] + end + + def required_x_tiles + left, bottom, right, top = bounding_box_in_tiles + Range.new(*[left, right].map(&:floor)).to_a + end + + def required_y_tiles + left, bottom, right, top = bounding_box_in_tiles + Range.new(*[top, bottom].map(&:floor)).to_a + end + + def required_tiles + required_y_tiles.map do |y| + required_x_tiles.map{|x| Tile.new(x,y,zoom) } + end.flatten + end + + def map_tiles + @map_tiles ||= tile_source.get_tiles(required_tiles) + end + + def crop_to_size(image) + distance_from_left = (bounding_box_in_tiles[0] - required_x_tiles[0]) * TILE_SIZE + distance_from_top = (bounding_box_in_tiles[3] - required_y_tiles[0]) * TILE_SIZE + + image.crop "#{width}x#{height}+#{distance_from_left}+#{distance_from_top}" + end + + def create_uncropped_image + image = MiniMagick::Image.read(map_tiles[0]) + + uncropped_width = required_x_tiles.length * TILE_SIZE + uncropped_height = required_y_tiles.length * TILE_SIZE + + image.combine_options do |c| + c.background 'none' + c.extent [uncropped_width, uncropped_height].join('x') + end + + image + end + + def fill_image_with_tiles(image) + start = 0 + + required_y_tiles.length.times do |row| + length = required_x_tiles.length + + map_tiles.slice(start, length).each_with_index do |tile, column| + image = image.composite( MiniMagick::Image.read(tile) ) do |c| + c.geometry "+#{ (column) * TILE_SIZE }+#{ (row) * TILE_SIZE }" + end + end + + start += length + end + + image + end + + end + end + end + end + end +end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/tile.rb b/lib/decidim/map/provider/static_map/cfj_osm/tile.rb new file mode 100644 index 000000000..7b226638f --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm/tile.rb @@ -0,0 +1,19 @@ +module Decidim + module Map + module Provider + module StaticMap + class CfjOsm < ::Decidim::Map::StaticMap + class Tile + attr_accessor :x, :y, :zoom + + def initialize(x, y, zoom) + @x = x.floor + @y = y.floor + @zoom = zoom + end + end + end + end + end + end +end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb b/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb new file mode 100644 index 000000000..1c3e10812 --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb @@ -0,0 +1,52 @@ +module Decidim + module Map + module Provider + module StaticMap + class CfjOsm < ::Decidim::Map::StaticMap + + # Tile Source + class TileSource + attr_reader :url, :organization + + def initialize(url, organization) + @url = url + @organization = organization + end + + def get_tiles(tiles) + responses = tiles.map do |tile| + request_url = tile_url(tile) + response = Faraday.get(request_url) do |req| + req.headers["Referer"] = organization.host + end + + response.body + end + end + + private + + attr_reader :connection + + def tile_url(tile) + url. + gsub(/\{x\}/, tile.x.to_s). + gsub(/\{y\}/, tile.y.to_s). + gsub(/\{z\}/, tile.zoom.to_s). + gsub(/\{s\}/, subdomain_for_tile(tile)) + end + + def subdomain_for_tile(tile) + i = (tile.x + tile.y) % subdomains.length + subdomains[i] + end + + def subdomains + ['a','b','c'] + end + end + end + end + end + end +end From c644f9a00aafc511d8f307d8732e41769e8ec2a1 Mon Sep 17 00:00:00 2001 From: takahashim Date: Mon, 5 Dec 2022 23:15:16 +0900 Subject: [PATCH 28/34] refactor: Tile is Struct --- .../map/provider/static_map/cfj_osm.rb | 3 --- .../map/provider/static_map/cfj_osm/map.rb | 18 +++++++++++------- .../map/provider/static_map/cfj_osm/tile.rb | 19 ------------------- 3 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 lib/decidim/map/provider/static_map/cfj_osm/tile.rb diff --git a/lib/decidim/map/provider/static_map/cfj_osm.rb b/lib/decidim/map/provider/static_map/cfj_osm.rb index 1759527df..72eeb8d10 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require_relative 'cfj_osm/conversion' -require_relative 'cfj_osm/tile' -require_relative 'cfj_osm/tile_source' require_relative 'cfj_osm/map' module Decidim diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb index e3e0e7d1f..3fdf1ce2a 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/map.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -1,15 +1,22 @@ +# frozen_string_literal: true + +require_relative 'conversion' +require_relative 'tile_source' + module Decidim module Map module Provider module StaticMap class CfjOsm < ::Decidim::Map::StaticMap + Tile = Struct.new(:x, :y, :zoom, keyword_init: true) + # static map generator (cf. https://github.com/crofty/mapstatic) class Map TILE_SIZE = 256 attr_reader :zoom, :lat, :lng, :width, :height - attr_accessor :tile_source + attr_reader :map_tiles def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) @lat = lat.to_f @@ -17,7 +24,8 @@ def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) @width = width.to_f @height = height.to_f @zoom = zoom.to_i - @tile_source = TileSource.new(provider, organization) + tile_source = TileSource.new(provider, organization) + @map_tiles = tile_source.get_tiles(required_tiles) end def width @@ -106,14 +114,10 @@ def required_y_tiles def required_tiles required_y_tiles.map do |y| - required_x_tiles.map{|x| Tile.new(x,y,zoom) } + required_x_tiles.map{|x| Tile.new(x: x.floor, y: y.floor, zoom: zoom) } end.flatten end - def map_tiles - @map_tiles ||= tile_source.get_tiles(required_tiles) - end - def crop_to_size(image) distance_from_left = (bounding_box_in_tiles[0] - required_x_tiles[0]) * TILE_SIZE distance_from_top = (bounding_box_in_tiles[3] - required_y_tiles[0]) * TILE_SIZE diff --git a/lib/decidim/map/provider/static_map/cfj_osm/tile.rb b/lib/decidim/map/provider/static_map/cfj_osm/tile.rb deleted file mode 100644 index 7b226638f..000000000 --- a/lib/decidim/map/provider/static_map/cfj_osm/tile.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Decidim - module Map - module Provider - module StaticMap - class CfjOsm < ::Decidim::Map::StaticMap - class Tile - attr_accessor :x, :y, :zoom - - def initialize(x, y, zoom) - @x = x.floor - @y = y.floor - @zoom = zoom - end - end - end - end - end - end -end From 3218205311b16869d5471c5710489d7d0ec9f38a Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 6 Dec 2022 01:15:39 +0900 Subject: [PATCH 29/34] refactor: extract BoundingBox --- .../map/provider/static_map/cfj_osm.rb | 3 - .../static_map/cfj_osm/bounding_box.rb | 61 +++++++++++++++++ .../map/provider/static_map/cfj_osm/map.rb | 65 +++---------------- 3 files changed, 70 insertions(+), 59 deletions(-) create mode 100644 lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb diff --git a/lib/decidim/map/provider/static_map/cfj_osm.rb b/lib/decidim/map/provider/static_map/cfj_osm.rb index 72eeb8d10..75198c199 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm.rb @@ -14,9 +14,6 @@ def image_data(latitude:, longitude:, options: {}) width = options[:width] || 120 height = options[:height] || 120 - Rails.logger.info("######################image_data###############") - Rails.logger.info([latitude, longitude, zoom, width, height]) - map = ::Decidim::Map::Provider::StaticMap::CfjOsm::Map.new( zoom: zoom, lat: latitude, diff --git a/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb b/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb new file mode 100644 index 000000000..484d7a4b3 --- /dev/null +++ b/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Decidim + module Map + module Provider + module StaticMap + class CfjOsm < ::Decidim::Map::StaticMap + class BoundingBox + TILE_SIZE = 256 + + attr_reader :lng, :lat, :width, :height, :zoom + attr_reader :left, :right, :top, :bottom + + def initialize(lng:, lat:, width:, height:, zoom:) + @lng = lng + @lat = lat + @width = width + @height = height + @zoom = zoom + + @left = Conversion.x_to_lng( to_x - ((width / TILE_SIZE) / 2), zoom) + @right = Conversion.x_to_lng( to_x + ((width / TILE_SIZE) / 2 ), zoom) + @top = Conversion.y_to_lat( to_y - ((height / TILE_SIZE) / 2 ), zoom) + @bottom = Conversion.y_to_lat( to_y + ((height / TILE_SIZE) / 2 ), zoom) + end + + def in_tiles_left + Conversion.lng_to_x(left, zoom) + end + + def in_tiles_right + Conversion.lng_to_x(right, zoom) + end + + def in_tiles_bottom + Conversion.lat_to_y(bottom, zoom) + end + + def in_tiles_top + Conversion.lat_to_y(top, zoom) + end + + def to_s + [left, right, top, bottom].join(',') + end + + private + + def to_x + Conversion.lng_to_x(lng, zoom) + end + + def to_y + Conversion.lat_to_y(lat, zoom) + end + end + end + end + end + end +end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb index 3fdf1ce2a..c3c51740f 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/map.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true +require 'mini_magick' + require_relative 'conversion' require_relative 'tile_source' +require_relative 'bounding_box' module Decidim module Map @@ -28,20 +31,6 @@ def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) @map_tiles = tile_source.get_tiles(required_tiles) end - def width - @width ||= begin - left, bottom, right, top = bounding_box_in_tiles - (right - left) * TILE_SIZE - end - end - - def height - @height ||= begin - left, bottom, right, top = bounding_box_in_tiles - (bottom - top) * TILE_SIZE - end - end - def to_image base_image = create_uncropped_image base_image = fill_image_with_tiles(base_image) @@ -55,7 +44,7 @@ def render_map(filename) def metadata { - :bbox => bounding_box.join(','), + :bbox => bounding_box.to_s, :width => width.to_i, :height => height.to_i, :zoom => zoom, @@ -65,51 +54,16 @@ def metadata private - def x_tile_space - Conversion.lng_to_x(lng, zoom) - end - - def y_tile_space - Conversion.lat_to_y(lat, zoom) - end - - def width_tile_space - width / TILE_SIZE - end - - def height_tile_space - height / TILE_SIZE - end - def bounding_box - @bounding_box ||= begin - left = Conversion.x_to_lng( x_tile_space - (width_tile_space / 2), zoom) - right = Conversion.x_to_lng( x_tile_space + ( width_tile_space / 2 ), zoom) - top = Conversion.y_to_lat( y_tile_space - ( height_tile_space / 2 ), zoom) - bottom = Conversion.y_to_lat( y_tile_space + ( height_tile_space / 2 ), zoom) - - [ left, bottom, right, top ] - end - end - - def bounding_box_in_tiles - left, bottom, right, top = bounding_box - [ - Conversion.lng_to_x(left, zoom), - Conversion.lat_to_y(bottom, zoom), - Conversion.lng_to_x(right, zoom), - Conversion.lat_to_y(top, zoom) - ] + @bounding_box ||= BoundingBox.new(lng: lng, lat: lat, width: width, height: height, zoom: zoom) end def required_x_tiles - left, bottom, right, top = bounding_box_in_tiles - Range.new(*[left, right].map(&:floor)).to_a + Range.new(*[bounding_box.in_tiles_left, bounding_box.in_tiles_right].map(&:floor)).to_a end def required_y_tiles - left, bottom, right, top = bounding_box_in_tiles - Range.new(*[top, bottom].map(&:floor)).to_a + Range.new(*[bounding_box.in_tiles_top, bounding_box.in_tiles_bottom].map(&:floor)).to_a end def required_tiles @@ -119,8 +73,8 @@ def required_tiles end def crop_to_size(image) - distance_from_left = (bounding_box_in_tiles[0] - required_x_tiles[0]) * TILE_SIZE - distance_from_top = (bounding_box_in_tiles[3] - required_y_tiles[0]) * TILE_SIZE + distance_from_left = (bounding_box.in_tiles_left - required_x_tiles[0]) * TILE_SIZE + distance_from_top = (bounding_box.in_tiles_top - required_y_tiles[0]) * TILE_SIZE image.crop "#{width}x#{height}+#{distance_from_left}+#{distance_from_top}" end @@ -156,7 +110,6 @@ def fill_image_with_tiles(image) image end - end end end From df001f6d9efff0ca98daf7fe93193deb99bf5d5b Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 6 Dec 2022 01:20:10 +0900 Subject: [PATCH 30/34] refactor: add render_as_binary --- lib/decidim/map/provider/static_map/cfj_osm.rb | 7 +------ lib/decidim/map/provider/static_map/cfj_osm/map.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/decidim/map/provider/static_map/cfj_osm.rb b/lib/decidim/map/provider/static_map/cfj_osm.rb index 75198c199..5036dcc6f 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm.rb @@ -24,12 +24,7 @@ def image_data(latitude:, longitude:, options: {}) organization: organization ) - Dir.mktmpdir do |dir| - tmpfile = File.join(dir, "map.png") - map.render_map(tmpfile) - - return File.binread(tmpfile) - end + map.render_as_binary end # @See Decidim::Map::StaticMap#url_params diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb index c3c51740f..7876c437e 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/map.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -42,6 +42,15 @@ def render_map(filename) to_image.write filename end + def render_as_binary + Dir.mktmpdir do |dir| + tmpfile = File.join(dir, "map.png") + render_map(tmpfile) + + return File.binread(tmpfile) + end + end + def metadata { :bbox => bounding_box.to_s, From 1a7ea90133872cfec39f79a6194d5de6fa205ade Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 6 Dec 2022 01:28:13 +0900 Subject: [PATCH 31/34] refactor: map_tiles is private --- lib/decidim/map/provider/static_map/cfj_osm/map.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb index 7876c437e..aac6c694c 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/map.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -19,7 +19,6 @@ class Map TILE_SIZE = 256 attr_reader :zoom, :lat, :lng, :width, :height - attr_reader :map_tiles def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) @lat = lat.to_f @@ -27,8 +26,7 @@ def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) @width = width.to_f @height = height.to_f @zoom = zoom.to_i - tile_source = TileSource.new(provider, organization) - @map_tiles = tile_source.get_tiles(required_tiles) + @tile_source = TileSource.new(provider, organization) end def to_image @@ -63,6 +61,10 @@ def metadata private + def map_tiles + @map_tiles ||= @tile_source.get_tiles(required_tiles) + end + def bounding_box @bounding_box ||= BoundingBox.new(lng: lng, lat: lat, width: width, height: height, zoom: zoom) end From 5e2b759bcdaf53eb179631aa3167d9bfa49fc4f3 Mon Sep 17 00:00:00 2001 From: takahashim Date: Tue, 6 Dec 2022 01:51:07 +0900 Subject: [PATCH 32/34] rubocop --- config/initializers/decidim.rb | 2 +- .../map/provider/static_map/cfj_osm.rb | 5 +-- .../static_map/cfj_osm/bounding_box.rb | 13 +++--- .../provider/static_map/cfj_osm/conversion.rb | 21 +++++----- .../map/provider/static_map/cfj_osm/map.rb | 41 +++++++++---------- .../static_map/cfj_osm/tile_source.rb | 17 ++++---- 6 files changed, 49 insertions(+), 50 deletions(-) diff --git a/config/initializers/decidim.rb b/config/initializers/decidim.rb index b602cbcd0..f296c634e 100644 --- a/config/initializers/decidim.rb +++ b/config/initializers/decidim.rb @@ -52,7 +52,7 @@ }, static: { provider: :cfj_osm, - url: 'http://www.openstreetmap.org/', + url: "http://www.openstreetmap.org/" }, # use StaticMap::CfjOsm geocoding: { host: "nominatim.openstreetmap.org", use_https: true } # autocomplete: { url: "https://nominatim.openstreetmap.org/search" } diff --git a/lib/decidim/map/provider/static_map/cfj_osm.rb b/lib/decidim/map/provider/static_map/cfj_osm.rb index 5036dcc6f..649e25308 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative 'cfj_osm/map' +require_relative "cfj_osm/map" module Decidim module Map @@ -9,7 +9,6 @@ module StaticMap # The static map utility class based on Osm class CfjOsm < ::Decidim::Map::StaticMap def image_data(latitude:, longitude:, options: {}) - zoom = options[:zoom] || 15 width = options[:width] || 120 height = options[:height] || 120 @@ -20,7 +19,7 @@ def image_data(latitude:, longitude:, options: {}) lng: longitude, width: width, height: height, - provider: 'http://tile.openstreetmap.jp/{z}/{x}/{y}.png', + provider: "http://tile.openstreetmap.jp/{z}/{x}/{y}.png", organization: organization ) diff --git a/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb b/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb index 484d7a4b3..d2a4e9632 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/bounding_box.rb @@ -8,8 +8,7 @@ class CfjOsm < ::Decidim::Map::StaticMap class BoundingBox TILE_SIZE = 256 - attr_reader :lng, :lat, :width, :height, :zoom - attr_reader :left, :right, :top, :bottom + attr_reader :lng, :lat, :width, :height, :zoom, :left, :right, :top, :bottom def initialize(lng:, lat:, width:, height:, zoom:) @lng = lng @@ -18,10 +17,10 @@ def initialize(lng:, lat:, width:, height:, zoom:) @height = height @zoom = zoom - @left = Conversion.x_to_lng( to_x - ((width / TILE_SIZE) / 2), zoom) - @right = Conversion.x_to_lng( to_x + ((width / TILE_SIZE) / 2 ), zoom) - @top = Conversion.y_to_lat( to_y - ((height / TILE_SIZE) / 2 ), zoom) - @bottom = Conversion.y_to_lat( to_y + ((height / TILE_SIZE) / 2 ), zoom) + @left = Conversion.x_to_lng(to_x - ((width / TILE_SIZE) / 2), zoom) + @right = Conversion.x_to_lng(to_x + ((width / TILE_SIZE) / 2), zoom) + @top = Conversion.y_to_lat(to_y - ((height / TILE_SIZE) / 2), zoom) + @bottom = Conversion.y_to_lat(to_y + ((height / TILE_SIZE) / 2), zoom) end def in_tiles_left @@ -41,7 +40,7 @@ def in_tiles_top end def to_s - [left, right, top, bottom].join(',') + [left, right, top, bottom].join(",") end private diff --git a/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb b/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb index 30b1a8ed3..5322bef6a 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/conversion.rb @@ -1,31 +1,32 @@ +# frozen_string_literal: true + module Decidim module Map module Provider module StaticMap class CfjOsm < ::Decidim::Map::StaticMap - # Math Converter class Conversion def self.lng_to_x(lng, zoom) - n = 2 ** zoom + n = 2**zoom ((lng.to_f + 180) / 360) * n end - def self.x_to_lng(x, zoom) - n = 2.0 ** zoom - lon_deg = x / n * 360.0 - 180.0 + def self.x_to_lng(x, zoom) # rubocop:disable Naming/MethodParameterName + n = 2.0**zoom + x / n * 360.0 - 180.0 end def self.lat_to_y(lat, zoom) - n = 2 ** zoom + n = 2**zoom lat_rad = (lat / 180) * Math::PI - (1 - Math.log( Math.tan(lat_rad) + (1 / Math.cos(lat_rad)) ) / Math::PI) / 2 * n + (1 - Math.log(Math.tan(lat_rad) + (1 / Math.cos(lat_rad))) / Math::PI) / 2 * n end - def self.y_to_lat(y, zoom) - n = 2.0 ** zoom + def self.y_to_lat(y, zoom) # rubocop:disable Naming/MethodParameterName + n = 2.0**zoom lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * y / n))) - lat_deg = lat_rad / (Math::PI / 180.0) + lat_rad / (Math::PI / 180.0) end end end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/map.rb b/lib/decidim/map/provider/static_map/cfj_osm/map.rb index aac6c694c..8ffc2eb10 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/map.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/map.rb @@ -1,17 +1,16 @@ # frozen_string_literal: true -require 'mini_magick' +require "mini_magick" -require_relative 'conversion' -require_relative 'tile_source' -require_relative 'bounding_box' +require_relative "conversion" +require_relative "tile_source" +require_relative "bounding_box" module Decidim module Map module Provider module StaticMap class CfjOsm < ::Decidim::Map::StaticMap - Tile = Struct.new(:x, :y, :zoom, keyword_init: true) # static map generator (cf. https://github.com/crofty/mapstatic) @@ -20,10 +19,10 @@ class Map attr_reader :zoom, :lat, :lng, :width, :height - def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) - @lat = lat.to_f - @lng = lng.to_f - @width = width.to_f + def initialize(zoom:, lat:, lng:, width:, height:, provider:, organization:) # rubocop:disable Metrics/ParameterLists + @lat = lat.to_f + @lng = lng.to_f + @width = width.to_f @height = height.to_f @zoom = zoom.to_i @tile_source = TileSource.new(provider, organization) @@ -51,11 +50,11 @@ def render_as_binary def metadata { - :bbox => bounding_box.to_s, - :width => width.to_i, - :height => height.to_i, - :zoom => zoom, - :number_of_tiles => required_tiles.length, + bbox: bounding_box.to_s, + width: width.to_i, + height: height.to_i, + zoom: zoom, + number_of_tiles: required_tiles.length } end @@ -79,13 +78,13 @@ def required_y_tiles def required_tiles required_y_tiles.map do |y| - required_x_tiles.map{|x| Tile.new(x: x.floor, y: y.floor, zoom: zoom) } + required_x_tiles.map { |x| Tile.new(x: x.floor, y: y.floor, zoom: zoom) } end.flatten end def crop_to_size(image) distance_from_left = (bounding_box.in_tiles_left - required_x_tiles[0]) * TILE_SIZE - distance_from_top = (bounding_box.in_tiles_top - required_y_tiles[0]) * TILE_SIZE + distance_from_top = (bounding_box.in_tiles_top - required_y_tiles[0]) * TILE_SIZE image.crop "#{width}x#{height}+#{distance_from_left}+#{distance_from_top}" end @@ -93,12 +92,12 @@ def crop_to_size(image) def create_uncropped_image image = MiniMagick::Image.read(map_tiles[0]) - uncropped_width = required_x_tiles.length * TILE_SIZE + uncropped_width = required_x_tiles.length * TILE_SIZE uncropped_height = required_y_tiles.length * TILE_SIZE image.combine_options do |c| - c.background 'none' - c.extent [uncropped_width, uncropped_height].join('x') + c.background "none" + c.extent [uncropped_width, uncropped_height].join("x") end image @@ -111,8 +110,8 @@ def fill_image_with_tiles(image) length = required_x_tiles.length map_tiles.slice(start, length).each_with_index do |tile, column| - image = image.composite( MiniMagick::Image.read(tile) ) do |c| - c.geometry "+#{ (column) * TILE_SIZE }+#{ (row) * TILE_SIZE }" + image = image.composite(MiniMagick::Image.read(tile)) do |c| + c.geometry "+#{column * TILE_SIZE}+#{row * TILE_SIZE}" end end diff --git a/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb b/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb index 1c3e10812..f5c86cadf 100644 --- a/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb +++ b/lib/decidim/map/provider/static_map/cfj_osm/tile_source.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true + module Decidim module Map module Provider module StaticMap class CfjOsm < ::Decidim::Map::StaticMap - # Tile Source class TileSource attr_reader :url, :organization @@ -14,7 +15,7 @@ def initialize(url, organization) end def get_tiles(tiles) - responses = tiles.map do |tile| + tiles.map do |tile| request_url = tile_url(tile) response = Faraday.get(request_url) do |req| req.headers["Referer"] = organization.host @@ -29,11 +30,11 @@ def get_tiles(tiles) attr_reader :connection def tile_url(tile) - url. - gsub(/\{x\}/, tile.x.to_s). - gsub(/\{y\}/, tile.y.to_s). - gsub(/\{z\}/, tile.zoom.to_s). - gsub(/\{s\}/, subdomain_for_tile(tile)) + url + .gsub(/\{x\}/, tile.x.to_s) + .gsub(/\{y\}/, tile.y.to_s) + .gsub(/\{z\}/, tile.zoom.to_s) + .gsub(/\{s\}/, subdomain_for_tile(tile)) end def subdomain_for_tile(tile) @@ -42,7 +43,7 @@ def subdomain_for_tile(tile) end def subdomains - ['a','b','c'] + %w(a b c) end end end From 47ee6392f05b246cbb81ac131944f9ca5e25c374 Mon Sep 17 00:00:00 2001 From: haya2 Date: Sat, 17 Dec 2022 17:11:27 +0900 Subject: [PATCH 33/34] change backgroundcolor from red to #FFFFFF --- app/packs/stylesheets/decidim/cfj/media_print.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/packs/stylesheets/decidim/cfj/media_print.scss b/app/packs/stylesheets/decidim/cfj/media_print.scss index 951af194f..11c9e3e4c 100644 --- a/app/packs/stylesheets/decidim/cfj/media_print.scss +++ b/app/packs/stylesheets/decidim/cfj/media_print.scss @@ -23,7 +23,7 @@ // common //---------------------------------- body { - background-color: red !important; + background-color: #FFFFFF !important; *, * > *, * > a, * > a:link, * > a:hover, * > a:visited, * > a:active { color: #000 !important; text-decoration: none !important; } } From 379afac600ed9a1133f3a11eefe8bb5a6936d763 Mon Sep 17 00:00:00 2001 From: ayuki_j <19406594+ayuki-joto@users.noreply.github.com> Date: Sun, 18 Dec 2022 01:38:33 +0900 Subject: [PATCH 34/34] refactor: change deploy env name --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5feed8542..42c98e844 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -37,8 +37,8 @@ jobs: id: set-env-production if: endsWith(github.ref, 'heads/master') || contains(github.ref, 'tags/v') run: | - echo "IMAGE_TAG_PREFIX=production-v0-25-2" >> $GITHUB_ENV - echo "EB_ENVIRONMENT_NAME=production-v0-25-2" >> $GITHUB_ENV + echo "IMAGE_TAG_PREFIX=prd-v0252" >> $GITHUB_ENV + echo "EB_ENVIRONMENT_NAME=prd-v0252" >> $GITHUB_ENV - name: Output App Env id: output-app-env