Currently, after graduating from programming school, I am creating a portfolio Post an error as a reminder that occurred during automatic deployment using Capistrano.
I introduced it by referring to the following article. If you don't know how to install it, please refer to it as I did. How to install automatic deployment tool (Capistrano)
When I installed Capistrano referring to the above article and executed automatic deployment, an error occurred on the way.
Terminal (local environment)
#Execute the following automatic deploy command in the application directory.
$ bundle exec cap production deploy
Click here for the details of the error after executing the automatic deploy command.
Terminal (local environment)
$ bundle exec cap production deploy
[Deprecation Notice] Future versions of Capistrano will not load the Git SCM
plugin by default. To silence this deprecation warning, add the following to
your Capfile after `require "capistrano/deploy"`:
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
00:00 git:wrapper
01 mkdir -p /tmp
✔ 01 [email protected] 0.239s
Uploading /tmp/git-ssh-smot-production-nakayakouyuu.sh 100.0%
02 chmod 700 /tmp/git-ssh-smot-production-nakayakouyuu.sh
✔ 02 [email protected] 0.291s
00:00 git:check
01 git ls-remote [email protected]:nakaya-kousuke/smot.git HEAD
01 5e943870f1583d9775b045f3c40d418324d8ad8a HEAD
✔ 01 [email protected] 2.098s
00:02 deploy:check:directories
01 mkdir -p /var/www/smot/shared /var/www/smot/releases
✔ 01 [email protected] 0.132s
00:03 deploy:check:linked_dirs
01 mkdir -p /var/www/smot/shared/log /var/www/smot/shared/tmp/pids /var/www/smot/shared/tmp/cache /var/www/smot/shared/tmp/sockets /var/www/smot/sha…
✔ 01 [email protected] 0.224s
00:03 git:clone
The repository mirror is at /var/www/smot/repo
00:03 git:update
01 git remote set-url origin [email protected]:nakaya-kousuke/smot.git
✔ 01 [email protected] 0.237s
02 git remote update --prune
02 Fetching origin
✔ 02 [email protected] 2.093s
00:06 git:create_release
01 mkdir -p /var/www/smot/releases/20201103133334
✔ 01 [email protected] 0.226s
02 git archive master | /usr/bin/env tar -x -f - -C /var/www/smot/releases/20201103133334
02 fatal: not a valid object name: master
02 tar:
02 This doesn't seem to be a tar archive
02
02 tar:
02 Exit with failure status due to previous error
02
#<Thread:0x00007f9e5507c1f0@/Users/nakaya-kousuke/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /Users/nakaya-kousuke/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/nakaya-kousuke/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as [email protected]: git exit status: 2 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar:This doesn't seem to be a tar archive
tar:Exit with failure status due to previous error
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: git exit status: 2
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar:This doesn't seem to be a tar archive
tar:Exit with failure status due to previous error
Caused by:
SSHKit::Command::Failed: git exit status: 2
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar:This doesn't seem to be a tar archive
tar:Exit with failure status due to previous error
Tasks: TOP => git:create_release
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as [email protected]: git exit status: 2
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar:This doesn't seem to be a tar archive
tar:Exit with failure status due to previous error
If you check the above error content, you can see that the error occurred in the ** git: create_release ** part.
Terminal (local environment) * Excerpt from the error text
00:06 git:create_release
01 mkdir -p /var/www/smot/releases/20201103133334
✔ 01 [email protected] 0.226s
02 git archive master | /usr/bin/env tar -x -f - -C /var/www/smot/releases/20201103133334
02 fatal: not a valid object name: master
02 tar:
02 This doesn't seem to be a tar archive
02
02 tar:
02 Exit with failure status due to previous error
02
fatal: not a valid object name: master This content seems to be the cause of this error, so It says "master is not a valid object name".
When I searched for ** fatal: not a valid object name: master **, I found many articles like the one below.
Remedy for Git error "fatal: Not a valid object name:'master'."
[Git] fatal: Not a valid object name:'master'. Solution
fatal: Not a valid object name:'master'. What happened when I was told?
[Git] fatal: Not a valid object name:'master' was angry [generally such a thing]
If you read this article, ** fatal: not a valid object name: master ** seems to be an error in Git.
Most articles tell me to "commit to the master branch", so do the following:
Terminal (local environment)
#Select all the files you want to commit
$ git add .
#Commit to master branch
$ git commit -m "fatal: not a valid object name:master error resolution"
#Execute automatic deploy command
$ bundle exec cap production deploy
** But this still didn't resolve the fatal: not a valid object name: master error! ** **
In Capistrano, I didn't get any articles with ** fatal: not a valid object name: master ** error, so I made a hypothesis.
I was told that "master is not a valid object name" and I knew it was a Git error. I'm using Git in the first place, and why can I push, commit, and pull on the master branch? ??
When I looked in the ** this doesn't seem to be a tar archive ** in the error statement, I found the following article:
capistrano error tar: this doesn't look like a tar archive
The best answer in this article says ** "I'm pulling a branch that doesn't exist from git" **, maybe I'm getting an error because the master branch doesn't exist in git? I made a hypothesis and investigated it.
When I checked GitHub under development, the default branch was ** "main" ** instead of "master"! !! !!
Therefore, I changed the git branch of Capistrano to "main".
config/deploy.rb
# config valid only for current version of Capistrano
#Described the version of capistrano. Continue to use the fixed version and prevent troubles due to version change
lock '3.14.1'
#Used to display Capistrano logs
set :application, 'smot'
#Specify from which repository you want to pull your app
set :repo_url, '[email protected]:nakaya-kousuke/smot.git'
----------Postscript----------
#Specify a branch
set :branch, "main"
--------------------------
#Specify a directory to be referenced in common even if the version changes
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')
set :rbenv_type, :user
set :rbenv_ruby, '2.5.1' #If you proceed according to the curriculum, 2.5.1 or 2.3.Is 1
#Which public key to use for deployment
set :ssh_options, auth_methods: ['publickey'],
keys: ['~/.ssh/smot.pem']
#Location of the file containing the process number
set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }
#Location of Unicorn configuration files
set :unicorn_config_path, -> { "#{current_path}/config/unicorn.rb" }
set :keep_releases, 5
# secrets.Added symbolic link for yml
set :linked_files, %w{ config/secrets.yml }
#Originally described after "'deploy:publishing', 'deploy:restart'Delete the following and rewrite as follows
after 'deploy:publishing', 'deploy:restart'
namespace :deploy do
task :restart do
invoke 'unicorn:restart'
end
desc 'upload secrets.yml'
task :upload do
on roles(:app) do |host|
if test "[ ! -d #{shared_path}/config ]"
execute "mkdir -p #{shared_path}/config"
end
upload!('config/secrets.yml', "#{shared_path}/config/secrets.yml")
end
end
before :starting, 'deploy:upload'
after :finishing, 'deploy:cleanup'
end
Terminal (local environment)
#Execute automatic deploy command
$ bundle exec cap production deploy
You have successfully successfully deployed automatically! !! !!
Why was the default branch on GitHub set to "main"? ?? ?? I checked.
■ Reference article GitHub, the default branch name of the repository to be created is "main". Change from "master" to "main"
** The default branch on GitHub has changed from "master" to "main"! ** **
This change is in the context of a human rights movement triggered by the May 25, 2020 incident in Minneapolis, Minnesota, USA.
I learned that such incidents can also affect the IT industry.
By the way, it seems that the default branch name of the newly created repository can be changed arbitrarily by setting GitHub.
Recommended Posts