Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken-Sumi1019 authored Aug 14, 2023
0 parents commit e818008
Show file tree
Hide file tree
Showing 77 changed files with 1,833 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "GitHub Codespaces (Default)",

"image": "mcr.microsoft.com/vscode/devcontainers/universal:2-linux",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"python.defaultInterpreterPath": "/opt/python/latest/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"lldb.executable": "/usr/bin/lldb",
"files.watcherExclude": {
"**/target/**": true
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"GitHub.vscode-pull-request-github",
"rebornix.Ruby",
"MS-vsliveshare.vsliveshare"
]
}
},

"remoteUser": "codespace",

"overrideCommand": false,

"mounts": ["source=codespaces-linux-var-lib-docker,target=/var/lib/docker,type=volume"],

"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--privileged",
"--init"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// "onCreateCommand": ". /etc/profile.d/rvm.sh && cd /workspaces/hr-eng-internship-2023-sample/rails && rvm install 3.0.6 && bundle install"
"onCreateCommand": "bash -c 'rvm install 3.0.6' && bash -i -c 'cd /workspaces/hr-eng-internship-2023-sample/rails && bundle install'",

// "oryx build" will automatically install your dependencies and attempt to build your project
"postCreateCommand": "oryx build -p virtualenv_name=.venv --log-file /tmp/oryx-build.log --manifest-dir /tmp || echo 'Could not auto-build. Skipping.'"

}
92 changes: 92 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: deploy-prod
on:
workflow_dispatch:

jobs:
build-and-push-rails-image:
runs-on: ubuntu-latest
timeout-minutes: 300

steps:
- uses: actions/checkout@v2

- name: "AWS 認証情報を設定"
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.APP_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.APP_AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1

- name: "AWS Parameter Store の値を環境変数に登録"
run: |
# 第1引数がparameter store上のパス, 第2引数が設定する環境変数の名前
function set_env_from_parameter_store() {
VALUE=$(aws ssm get-parameter --name $1 --with-decryption --query 'Parameter.Value' --output text)
echo "$2=$VALUE" >> $GITHUB_ENV
echo "::add-mask::$VALUE"
}
set_env_from_parameter_store '/internship/rails/RAILS_MASTER_KEY' 'RAILS_MASTER_KEY'
- name: "Amazon ECR にログイン"
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: "Docker リポジトリ用のタグを環境変数に設定"
id: set-env
run: |
ECR_URI=${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY=hr-eng-internship-2023
ref=${{ github.ref }}
REF_NAME=${ref#refs/heads/*}
TAG_NAME=$(echo $REF_NAME | sed -e 's/\//\-/g')
GITHUB_SHA=${{ github.sha }}
ECR_REPOSITORY_URI=$ECR_URI/$ECR_REPOSITORY
echo "REF_NAME=$REF_NAME" >> $GITHUB_ENV
echo "GITHUB_SHA=$GITHUB_SHA" >> $GITHUB_ENV
echo "ECR_REPOSITORY_URI=$ECR_REPOSITORY_URI" >> $GITHUB_ENV
echo "IMAGE_TAG=$ECR_REPOSITORY_URI:$GITHUB_SHA" >> $GITHUB_ENV
echo "CACHE_TAG=$ECR_REPOSITORY_URI:build-cache" >> $GITHUB_ENV
# 人間が読みやすいようにブランチ名のタグを用意する
echo "POINTER_TAG=$ECR_REPOSITORY_URI:$TAG_NAME" >> $GITHUB_ENV
- name: "Docker イメージのビルド"
run: |
docker pull "$CACHE_TAG" || true
docker build \
-f docker/Dockerfile \
-t $IMAGE_TAG \
--cache-from "$CACHE_TAG" \
\
--build-arg RAILS_MASTER_KEY=$RAILS_MASTER_KEY \
.
working-directory: rails

- name: "Amazon ECR へイメージをプッシュ"
run: |
docker push $IMAGE_TAG
# 次回のビルドのためにキャッシュイメージをpush
docker tag $IMAGE_TAG $CACHE_TAG
docker push $CACHE_TAG
# 人間がECRを見たときにどのイメージがデプロイされているかを認識しやすいようにタグする
docker tag $IMAGE_TAG $POINTER_TAG
docker push $POINTER_TAG
working-directory: rails

deploy:
uses: speee/dx-reusable-workflows/.github/workflows/application-deploy.yml@main
needs:
- build-and-push-rails-image

with:
env_name: internship
repository_name: dx-sandbox-infra
branch: production
ecr_repository_names: |
hr-eng-internship-2023
git_user_name: sandbox
git_user_email: sandbox@speee.jp
enable_slack_notify: false
secrets:
aws_access_key_id: ${{ secrets.APP_AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.APP_AWS_SECRET_ACCESS_KEY }}
ci_user_access_token: ${{ secrets.PERSONAL_ACCESS_TOKEN_OF_SPEEE_IEUL_GITHUB_USER }}
36 changes: 36 additions & 0 deletions .github/workflows/rails-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'on':
pull_request:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: rails
services:
db:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
TZ: 'Asia/Tokyo'
ports:
- 3306:3306
env:
RAILS_ENV: test
TZ: 'Asia/Tokyo'
timeout-minutes: 10
steps:
- uses: actions/checkout@v3

# https://docs.github.com/en/enterprise-cloud@latest/actions/automating-builds-and-tests/building-and-testing-ruby
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
working-directory: rails

- run: bundle exec rails db:create db:migrate
- name: rspec
run: bundle exec rspec
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
*.rbc
capybara-*.html
.rspec
/db/*.sqlite3
/db/*.sqlite3-journal
/db/*.sqlite3-[0-9]*
/public/system
/coverage/
/spec/tmp
*.orig
rerun.txt
pickle-email-*.html

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# TODO Comment out this rule if you are OK with secrets being uploaded to the repo
config/initializers/secret_token.rb
config/master.key

# Only include if you have production secrets in this file, which is no longer a Rails default
# config/secrets.yml

# dotenv, dotenv-rails
# TODO Comment out these rules if environment variables can be committed
.env
.env*.local

## Environment normalization:
/.bundle
/vendor/bundle

# these should all be checked in to normalize the environment:
# Gemfile.lock, .ruby-version, .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc

# if using bower-rails ignore default bower_components path bower.json files
/vendor/assets/bower_components
*.bowerrc
bower.json

# Ignore pow environment settings
.powenv

# Ignore Byebug command history file.
.byebug_history

# Ignore node_modules
node_modules/

# Ignore precompiled javascript packs
/public/packs
/public/packs-test
/public/assets

# Ignore yarn files
/yarn-error.log
yarn-debug.log*
.yarn-integrity

# Ignore uploaded files in development
/storage/*
!/storage/.keep
/public/uploads
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# hr-eng-internship-2023-sample
2023年のインターンシップのサンプルアプリケーション
7 changes: 7 additions & 0 deletions rails/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
31 changes: 31 additions & 0 deletions rails/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

/public/assets

# Ignore master key for decrypting credentials and more.
/config/master.key
1 change: 1 addition & 0 deletions rails/.ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.6
75 changes: 75 additions & 0 deletions rails/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.0.6"

# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.0.6"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

# Use mysql as the database for Active Record
gem "mysql2", "~> 0.5"

# Use the Puma web server [https://github.com/puma/puma]
gem "puma", "~> 5.0"

# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails]
gem "importmap-rails"

# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev]
gem "turbo-rails"

# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev]
gem "stimulus-rails"

# Build JSON APIs with ease [https://github.com/rails/jbuilder]
gem "jbuilder"

gem 'komachi_heartbeat', '~> 2.5'

# Use Redis adapter to run Action Cable in production
# gem "redis", "~> 4.0"

# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
# gem "kredis"

# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", require: false

# Use Sass to process CSS
# gem "sassc-rails"

# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri mingw x64_mingw ]
end

group :development do
# Use console on exceptions pages [https://github.com/rails/web-console]
gem "web-console"

# Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
# gem "rack-mini-profiler"

# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
# gem "spring"
end

group :test do
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
gem 'rspec-rails'
end
Loading

0 comments on commit e818008

Please sign in to comment.