This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from akiko-pusu/dev
Update version to 0.2.1.
- Loading branch information
Showing
15 changed files
with
575 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
# | ||
# Check https://circleci.com/docs/2.0/language-ruby/ for more details | ||
# | ||
version: 2 | ||
orbs: | ||
aws-ecr: circleci/[email protected] | ||
|
||
version: 2.1 | ||
|
||
general: | ||
artifacts: | ||
|
@@ -55,17 +58,66 @@ jobs: | |
cp -r coverage/${CIRCLE_PROJECT_REPONAME}_test /tmp/coverage/ | ||
- store_artifacts: | ||
path: /tmp/coverage | ||
deploy_heroku: | ||
machine: | ||
image: circleci/classic:edge | ||
steps: | ||
- checkout | ||
- run: | ||
name: 'Install Heroku CLI, if necessary' | ||
command: | | ||
curl https://cli-assets.heroku.com/install.sh | sh | ||
- run: | ||
name: 'Build Docker Image' | ||
command: | | ||
heroku -v | ||
docker build --build-arg=COMMIT=${CIRCLE_SHA1} \ | ||
--build-arg=BRANCH=${CIRCLE_BRANCH} -t registry.heroku.com/${HEROKU_APP_NAME}/web . | ||
- run: | ||
name: 'Release Docker Image' | ||
command: | | ||
docker login --username=_ --password=$HEROKU_AUTH_TOKEN registry.heroku.com | ||
docker push registry.heroku.com/${HEROKU_APP_NAME}/web | ||
#heroku container:push web --app ${HEROKU_APP_NAME} | ||
heroku container:release web --app ${HEROKU_APP_NAME} | ||
workflows: | ||
version: 2 | ||
build_and_test: | ||
build_test_push: | ||
jobs: | ||
- build | ||
- build: | ||
filters: | ||
branches: | ||
ignore: | ||
- /ignore-build-.*/ | ||
- test: | ||
requires: | ||
- build | ||
filters: | ||
branches: | ||
ignore: | ||
- /v0.1.x-support-Redmine3.*/ | ||
- aws-ecr/build-and-push-image: | ||
account-url: AWS_ECR_ACCOUNT_URL | ||
aws-access-key-id: AWS_ACCESS_KEY_ID | ||
aws-secret-access-key: AWS_SECRET_ACCESS_KEY | ||
create-repo: true | ||
dockerfile: Dockerfile | ||
path: . | ||
region: AWS_REGION | ||
repo: redmine_banner | ||
extra-build-args: '--build-arg COMMIT=$CIRCLE_SHA1 --build-arg=BRANCH=$CIRCLE_BRANCH' | ||
requires: | ||
- test | ||
filters: | ||
branches: | ||
only: | ||
- master | ||
- deploy_heroku: | ||
requires: | ||
- build | ||
filters: | ||
branches: | ||
ignore: | ||
- master | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,59 @@ | ||
# | ||
# docker build --build-arg=COMMIT=$(git rev-parse --short HEAD) \ | ||
# --build-arg=BRANCH=$(git name-rev --name-only HEAD) -t akiko/redmine_banner:latest . | ||
# | ||
# | ||
FROM ruby:2.5 | ||
LABEL maintainer="AKIKO TAKANO / (Twitter: @akiko_pusu)" \ | ||
description="Image to run Redmine simply with sqlite to try/review plugin." | ||
|
||
ARG BRANCH="master" | ||
ARG COMMIT="commit_sha" | ||
|
||
ENV COMMIT_SHA=${COMMIT} | ||
ENV COMMIT_BRANCH=${BRANCH} | ||
|
||
RUN mkdir /app | ||
|
||
### get Redmine source | ||
### Replace shell with bash so we can source files ### | ||
RUN rm /bin/sh && ln -s /bin/bash /bin/sh | ||
|
||
### install default sys packeges ### | ||
|
||
RUN apt-get update | ||
RUN apt-get install -qq -y \ | ||
RUN apt-get install -qq -y --no-install-recommends \ | ||
git vim subversion \ | ||
sqlite3 default-libmysqlclient-dev | ||
RUN apt-get install -qq -y build-essential libc6-dev | ||
sqlite3 && rm -rf /var/lib/apt/lists/* | ||
|
||
RUN cd /tmp && svn co http://svn.redmine.org/redmine/branches/4.0-stable/ redmine | ||
WORKDIR /tmp/redmine | ||
RUN cd /app && svn co http://svn.redmine.org/redmine/branches/4.0-stable/ redmine | ||
WORKDIR /app/redmine | ||
|
||
COPY . /app/redmine/plugins/redmine_banner/ | ||
|
||
# add database.yml (for development, development with mysql, test) | ||
RUN echo $'test:\n\ | ||
adapter: sqlite3\n\ | ||
database: /tmp/data/redmine_test.sqlite3\n\ | ||
database: /app/data/redmine_test.sqlite3\n\ | ||
encoding: utf8mb4\n\ | ||
development:\n\ | ||
adapter: sqlite3\n\ | ||
database: /tmp/data/redmine_development.sqlite3\n\ | ||
encoding: utf8mb4\n\ | ||
development_mysql:\n\ | ||
adapter: mysql2\n\ | ||
host: mysql\n\ | ||
password: pasword\n\ | ||
database: redemine_development\n\ | ||
username: root\n'\ | ||
database: /app/data/redmine_development.sqlite3\n\ | ||
encoding: utf8mb4\n'\ | ||
>> config/database.yml | ||
|
||
RUN gem update bundler | ||
RUN bundle install --without postgresql rmagick | ||
RUN bundle exec rake db:migrate | ||
|
||
RUN bundle install --without postgresql rmagick mysql | ||
RUN bundle exec rake db:migrate && bundle exec rake redmine:plugins:migrate \ | ||
&& bundle exec rake generate_secret_token | ||
RUN bundle exec rails runner \ | ||
"Setting.send('plugin_redmine_banner=', {enable: 'true', type: 'info', display_part: 'both', banner_description: 'This is a test message for Global Banner. (${COMMIT_BRANCH}:${COMMIT_SHA})'}.stringify_keys)" | ||
|
||
# Change Admin's password to 'redmine_banner_${COMMIT_SHA}' | ||
# Default is 'redmine_banner_commit_sha' | ||
RUN bundle exec rails runner \ | ||
"User.find_by_login('admin').update!(password: 'redmine_banner_${COMMIT_SHA}', must_change_passwd: false)" | ||
|
||
EXPOSE 3000 | ||
RUN ls /app/redmine | ||
CMD ["rails", "server", "-b", "0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# frozen_string_literal: true | ||
|
||
module Banners | ||
module Api | ||
class GlobalBannerController < ApplicationController | ||
# TODO: This group should be customize. | ||
GLOBAL_BANNER_ADMIN_GROUP = 'GlobalBanner_Admin' | ||
|
||
before_action :require_login, :require_banner_admin | ||
accept_api_auth :show, :register_banner | ||
|
||
def show | ||
render json: global_banner_json | ||
end | ||
|
||
def register_banner | ||
begin | ||
global_banner_params = build_params | ||
rescue ActionController::ParameterMissing, ActionController::UnpermittedParameters => e | ||
response_bad_request(e.message) && (return) | ||
end | ||
|
||
retval = Setting.send('plugin_redmine_banner=', global_banner_params.stringify_keys) | ||
|
||
if retval | ||
render status: 200, json: { status: 'OK', message: 'updating the global banner' } | ||
else | ||
response_bad_request("Can't save data to settings table.") | ||
end | ||
rescue StandardError => e | ||
response_internal_server_error(e.message) | ||
end | ||
|
||
private | ||
|
||
# TODO: Private methods should be refactoring. | ||
# TODO: Validation is required | ||
def build_params | ||
valid_params(params) | ||
end | ||
|
||
def global_banner_json | ||
{ global_banner: Setting['plugin_redmine_banner'] } | ||
end | ||
|
||
# 400 Bad Request | ||
def response_bad_request(error_message = nil) | ||
json_data = { status: 400, message: 'Bad Request' } | ||
json_data.merge!(reason: error_message) if error_message.present? | ||
logger.warn("Global Banner Update failed. Caused: #{json_data}") | ||
render status: 400, json: json_data | ||
end | ||
|
||
# 401 Unauthorized | ||
def response_unauthorized | ||
render status: 401, json: { status: 401, message: 'Unauthorized' } | ||
end | ||
|
||
# 500 Internal Server Error | ||
def response_internal_server_error(error_message = nil) | ||
json_data = { status: 500, message: 'Internal Server Error' } | ||
json_data.merge!(reason: error_message) if error_message.present? | ||
logger.warn("Global Banner Update failed. Caused: #{json_data}") | ||
render status: 500, json: json_data | ||
end | ||
|
||
def require_banner_admin | ||
return if User.current.admin? || banner_admin?(User.current) | ||
|
||
response_unauthorized | ||
end | ||
|
||
def banner_admin?(user) | ||
banner_admin_group = Group.find_by_lastname(GLOBAL_BANNER_ADMIN_GROUP) | ||
return false if banner_admin_group.blank? | ||
|
||
banner_admin_group.users.include?(user) | ||
end | ||
|
||
def valid_params(params) | ||
params.require(:global_banner).permit( | ||
:banner_description, | ||
:display_part, | ||
:enable, | ||
:end_hour, :end_min, :end_ymd, | ||
:related_link, | ||
:start_hour, :start_min, :start_ymd, | ||
:type, | ||
:use_timer | ||
) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.