1.Create a repository with any name
2.public settings
3.Click "create repository"
4.User Setting
-#Do it in the app directory
% git config user.name "user name"
% git config user.email “github registration email”
-#Confirm that the set user name and email are registered.
% git config user.name
% git config user.email
5.Linking remote repositories
%git remote add origin repository URL.git
-#Confirmation of linking
% git remote -v
% git add .
% git commit -m ‘first commit’
% git push origin master
Check if the app can be pushed to the repository.
1.Click Sign in in the upper right
2.Click "SIGN IN WITH GIT HUB"
3.「Authorize travis-Click "ci"
4.Enter information on Github
5.left"+Click
6.Click on any repository to sync
7.Click "Dashbord" at the top and make sure you have the selected repository in "Active repositories".
-#Create in the app's home directory
% vim .travis.yaml
yaml:.travis.yaml
#Run with sudo privileges
sudo: required
#Declaration of use of docker
services: docker
#Start container
before_install:
- docker-compose up --build -d
script:
#DB preparation
- docker-compose exec —env 'RAILS_ENV=test' web rails db:create
- docker-compose exec —env 'RAILS_ENV=test' web rails db:migrate
#Run the test
- docker-compose exec —env 'RAILS_ENV=test' web rails test
You need to push the code to github to get Travi CI working.
docker-compose.description of yml
version: '3'
#docker volume Data is saved here
volumes:
db-data:
services:
web:
build: .
ports:
- '3000:3000'
volumes:
- '.:/product-register'
#Environment variable settings of the container, originally the password should not be written directly.
environment:
- 'DATABASE_PASSWORD=postgres'
tty: true
stdin_open: true
#Created once the db service is created
depends_on:
- db
#You can access db from the web
links:
- db
#postgres container
db:
image: postgres
#Host db-Store data in data
volumes:
- 'db-data:/var/lib/postgresql/data'
environment:
- 'POSTGRES_USER=postgres'
- 'POSTGRES_PASSWORD=postgres'
#Required if you want to run postgres on other than localhost
- 'POSTGRES_HOST_AUTH_METHOD=trust'
% git add .
% git commit -m ‘update travis and compose’
% git push origin master
Here you can see the actual execution situation on the travis page.
1.log in
2.Click "create new app"
3.Enter any name in "APP name".
4.Click "Create app"
5.Click "Resources" when it is created.
6.「Add-Search for postgres with "ons". Select "Heroku Postgres"
7.Click "Provision".
8.Click "Settings", then click "Reveal Config Vars".
9.config/master.Enter the value of key in VALUE.
10.Enter "SECRET" for KEY_KEY_Enter "BASE".
11.Click "Add".
12.Click the "Deploy" tab.
13.Click on GitHub for "Deployment method"
14.Enter the name of the repository in "Connect to GitHub" and click "Search"
15.Click "Connet" in any repository
16.Wait for CI to pass before deploy in "Automatic deploys"(Deploy after passing CI)Check to.
17.Click "Enable Automatic Deploy"
config/databese.yml
# You can use this database configuration with:
#
production:
url: <%= ENV['DATABASE_URL'] %>
#
# production:
# <<: *default
# database: product-register_production
# username: product-register
# password: <%= ENV['PRODUCT-REGISTER_DATABASE_PASSWORD'] %>
yml:.travis.yml
#Run with sudo privileges
sudo: required
#Declaration of use of docker
services: docker
#Start container
before_install:
- docker-compose up --build -d
#Log in to Heroku's Docker registry
- docker login -u "$HEROKU_USERNAME" -p "$HEROKU_API_KEY" registry.heroku.com
script:
#DB preparation
- docker-compose exec --env 'RAILS_ENV=test' web rails db:create
- docker-compose exec --env 'RAILS_ENV=test' web rails db:migrate
#Run the test
- docker-compose exec --env 'RAILS_ENV=test' web rails test
deploy:
provider: script
script:
docker build -t registry.heroku.com/$HEROKU_API_NAME/web -f Dockerfile.prod .;
docker push registry.heroku.com/$HEROKU_API_NAME/web;
heroku run --app $HEROKU_API_NAME rails db:migrate;
on:
branch: master
If you add a comment out, you will see problems, so it is better not to add it as much as possible.
-# Heroku-install cli
% brew tap heroku/brew && brew install heroku
-#Get Token
% heroku authorizations:create
% vim Dockerfile.prod
Dockerfile.prod
FROM ruby:2.5
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
nodejs \
postgresql-client \
yarn
WORKDIR /product-register
COPY Gemfile Gemfile.lock /product-register/
RUN bundle install
#Move all the code in the current directory to the container
COPY . .
#Start rails server
CMD [ "rails", "s"]
% git add .
% git commit -m ’add deploy code’
% git push origin master
Recommended Posts