{"id":10817,"date":"2020-08-12T16:04:05","date_gmt":"2020-08-12T07:04:05","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=10817"},"modified":"2025-09-02T17:09:13","modified_gmt":"2025-09-02T08:09:13","slug":"github-actions-%eb%b0%b0%ed%8f%ac-%ec%84%a4%ec%a0%95-%ea%b0%80%ec%9d%b4%eb%93%9c","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=10817","title":{"rendered":"GitHub Actions \ubc30\ud3ec \uc124\uc815 \uac00\uc774\ub4dc"},"content":{"rendered":"<h1>GitHub Actions \ubc30\ud3ec \uc124\uc815 \uac00\uc774\ub4dc<\/h1>\n<p>GitHub \uc5d0 Push \uac00 \uc774\ub8e8\uc5b4\uc84c\uc744 \ub54c, \ub2e8\uc77c \uc6f9\uc11c\ubc84\uc5d0 \ubc30\ud3ec\ud558\ub294 workflow \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4.<\/p>\n<h2>workflow \ud30c\uc77c \uc0dd\uc131<\/h2>\n<p>.github\/workflows\/deploy.yml<\/p>\n<pre><code class=\"language-yaml\">name: Deploy to Production\n\non:\n  push:\n    branches: [ main ]\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n\n    steps:\n    - name: Checkout code\n      uses: actions\/checkout@v4\n\n    - name: Deploy to server\n      uses: appleboy\/ssh-action@v1.0.3\n      with:\n        host: ${{ secrets.HOST }}\n        username: ${{ secrets.USERNAME }}\n        key: ${{ secrets.SSH_KEY }}\n        script: |\n          cd \/home\/deploy\/web-repo\n          git fetch origin\n          git reset --hard origin\/main\n\n          # \/src \ub514\ub809\ud1a0\ub9ac \ub0b4\uc6a9\uc744 \uc6f9 \ub514\ub809\ud1a0\ub9ac\ub85c \ubcf5\uc0ac\n          if [ -d &quot;src&quot; ]; then\n            sudo rsync -av --delete src\/ \/var\/www\/html\/\n            sudo chown -R www-data:www-data \/var\/www\/html\n            sudo chmod -R 755 \/var\/www\/html\n            echo &quot;$(date): Deployment completed via GitHub Actions&quot; | sudo tee -a \/var\/log\/deploy.log\n          else\n            echo &quot;ERROR: \/src directory not found&quot;\n            exit 1\n          fi\n\n          # nginx \uc124\uc815 \ud14c\uc2a4\ud2b8 \ubc0f \uc7ac\ub85c\ub4dc\n          sudo nginx -t &amp;&amp; sudo systemctl reload nginx<\/code><\/pre>\n<h2>\uc11c\ubc84 \uc124\uc815 (example.com)<\/h2>\n<h3>deploy \uacc4\uc815 \uc0dd\uc131<\/h3>\n<pre><code class=\"language-bash\">sudo adduser deploy\nsudo usermod -aG sudo deploy<\/code><\/pre>\n<h3>deploy \uacc4\uc815\uc73c\ub85c \uc804\ud658 \ud6c4 \ub514\ub809\ud1a0\ub9ac \uc124\uc815<\/h3>\n<p>\uc800\uc7a5\uc18c\uac00 Private \uc778 \uacbd\uc6b0 <code>Personal Access Token<\/code> \uc124\uc815\uc744 \ubbf8\ub9ac \ud574 \uc8fc\uc5b4\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\">sudo su - deploy\nmkdir -p \/home\/deploy\/web-repo\ncd \/home\/deploy\/web-repo\n\n# \uc800\uc7a5\uc18c \ud074\ub860 (\ucd5c\ucd08 1\ud68c)\ngit clone https:\/\/github.com\/YOUR_USERNAME\/YOUR_REPOSITORY.git .<\/code><\/pre>\n<p>Private Repo \uc778\uacbd\uc6b0 Personal Access Token \ub97c \uc800\uc7a5\ud574 \uc8fc\uc5b4\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<pre><code class=\"language-bash\"># GitHub\uc5d0\uc11c Personal Access Token \uc0dd\uc131 \ud6c4\ngit config --global credential.helper store\ngit config --global user.name &quot;myname&quot;\ngit config --global user.email &quot;myname@gmail.com&quot;\n\n# \ub2e4\uc74c git \uba85\ub839 \uc2e4\ud589\uc2dc PAT\ub97c \ud328\uc2a4\uc6cc\ub4dc\ub85c \uc785\ub825 (\ud55c \ubc88\ub9cc)\ngit fetch origin<\/code><\/pre>\n<h3>SSH \ud0a4 \uc0dd\uc131<\/h3>\n<pre><code class=\"language-bash\"># deploy \uacc4\uc815\uc5d0\uc11c \uc2e4\ud589\nssh-keygen -t rsa -b 4096 -C &quot;deploy@example.com&quot;\n# Enter 3\ubc88 \ub20c\ub7ec\uc11c \uae30\ubcf8 \uc124\uc815\uc73c\ub85c \uc0dd\uc131\n\n# \uacf5\uac1c\ud0a4 \ud655\uc778 (GitHub\uc5d0 \ub4f1\ub85d\uc6a9)\ncat ~\/.ssh\/id_rsa.pub\n\n# \uac1c\uc778\ud0a4 \ud655\uc778 (GitHub Secrets\uc5d0 \ub4f1\ub85d\uc6a9)\ncat ~\/.ssh\/id_rsa<\/code><\/pre>\n<h3>SSH \uc778\uc99d \uc124\uc815<\/h3>\n<pre><code class=\"language-bash\"># deploy \uacc4\uc815\uc5d0\uc11c \uc2e4\ud589\ncat ~\/.ssh\/id_rsa.pub &gt;&gt; ~\/.ssh\/authorized_keys\nchmod 600 ~\/.ssh\/authorized_keys\nchmod 700 ~\/.ssh<\/code><\/pre>\n<h3>sudo \uad8c\ud55c \uc124\uc815 (\ube44\ubc00\ubc88\ud638 \uc5c6\uc774 \uc2e4\ud589)<\/h3>\n<pre><code class=\"language-bash\"># root \uacc4\uc815\uc5d0\uc11c \uc2e4\ud589\nsudo visudo\n\n# \ud30c\uc77c \ub05d\uc5d0 \ub2e4\uc74c \uc904 \ucd94\uac00:\ndeploy ALL=(ALL) NOPASSWD: \/usr\/bin\/rsync, \/bin\/chown, \/bin\/chmod, \/usr\/bin\/tee, \/usr\/sbin\/nginx, \/bin\/systemctl<\/code><\/pre>\n<h3>\uc6f9 \ub514\ub809\ud1a0\ub9ac \uad8c\ud55c \uc124\uc815<\/h3>\n<pre><code class=\"language-bash\"># root \uacc4\uc815\uc5d0\uc11c \uc2e4\ud589\nsudo mkdir -p \/var\/www\/html\nsudo chown deploy:www-data \/var\/www\/html\nsudo chmod 755 \/var\/www\/html<\/code><\/pre>\n<h2>GitHub \uc800\uc7a5\uc18c \uc124\uc815<\/h2>\n<h3>Deploy Key \ub4f1\ub85d (\uc800\uc7a5\uc18c\ubcc4)<\/h3>\n<ul>\n<li>GitHub \uc800\uc7a5\uc18c \u2192 Settings \u2192 Deploy keys<\/li>\n<li>&quot;Add deploy key&quot; \ud074\ub9ad<\/li>\n<li>Title: deploy@example.com<\/li>\n<li>Key: \uc55e\uc11c \uc0dd\uc131\ud55c \uacf5\uac1c\ud0a4(~\/.ssh\/id_rsa.pub \ub0b4\uc6a9) \ubd99\uc5ec\ub123\uae30<\/li>\n<li>&quot;Allow write access&quot; \uccb4\ud06c<\/li>\n<li>&quot;Add key&quot; \ud074\ub9ad<\/li>\n<\/ul>\n<h3>Repository Secrets \ub4f1\ub85d<\/h3>\n<ul>\n<li>GitHub \uc800\uc7a5\uc18c \u2192 Settings \u2192 Secrets and variables \u2192 Actions<\/li>\n<li>\ub2e4\uc74c \uc2dc\ud06c\ub9bf\ub4e4\uc744 &quot;New repository secret&quot;\uc73c\ub85c \ucd94\uac00:<\/li>\n<\/ul>\n<p>HOST: example.com<\/p>\n<p>USERNAME: deploy<\/p>\n<p>SSH_KEY:<\/p>\n<p>\/home\/deploy\/.ssh\/id_rsa \ud30c\uc77c\uc758 \uc804\uccb4 \ub0b4\uc6a9<br \/>\n&#8212;&#8211;BEGIN OPENSSH PRIVATE KEY&#8212;&#8211;<br \/>\n(\uac1c\uc778\ud0a4 \ub0b4\uc6a9)<br \/>\n&#8212;&#8211;END OPENSSH PRIVATE KEY&#8212;&#8211;<\/p>\n<h2>\uc11c\ubc84 \ud658\uacbd \ud655\uc778<\/h2>\n<h3>\ud544\uc218 \ud328\ud0a4\uc9c0 \uc124\uce58 \ud655\uc778<\/h3>\n<pre><code class=\"language-bash\"># nginx \uc124\uce58 \ud655\uc778\nsudo systemctl status nginx\n\n# rsync \uc124\uce58 \ud655\uc778\nrsync --version\n\n# git \uc124\uce58 \ud655\uc778\ngit --version<\/code><\/pre>\n<h3>\ub85c\uadf8 \ub514\ub809\ud1a0\ub9ac \uc124\uc815<\/h3>\n<pre><code class=\"language-bash\">sudo mkdir -p \/var\/log\nsudo touch \/var\/log\/deploy.log\nsudo chown deploy:deploy \/var\/log\/deploy.log<\/code><\/pre>\n<h2>\ud14c\uc2a4\ud2b8<\/h2>\n<h3>\ub85c\uceec\uc5d0\uc11c SSH \uc5f0\uacb0 \ud14c\uc2a4\ud2b8<\/h3>\n<pre><code class=\"language-bash\">ssh -i ~\/.ssh\/id_rsa deploy@example.com<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>GitHub Actions \ubc30\ud3ec \uc124\uc815 \uac00\uc774\ub4dc GitHub \uc5d0 Push \uac00 \uc774\ub8e8\uc5b4\uc84c\uc744 \ub54c, \ub2e8\uc77c \uc6f9\uc11c\ubc84\uc5d0 \ubc30\ud3ec\ud558\ub294 workflow \ub97c \uc0dd\uc131\ud569\ub2c8\ub2e4. workflow \ud30c\uc77c \uc0dd\uc131 .github\/workflows\/deploy.yml name: Deploy to Production on: push: branches: [ main ] jobs: deploy: runs-on: ubuntu-latest steps: &#8211; name: Checkout code uses: actions\/checkout@v4 &#8211; name: Deploy to server uses: appleboy\/ssh-action@v1.0.3 with: host: ${{ secrets.HOST }} username:\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=10817\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-10817","post","type-post","status-publish","format-standard","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10817"}],"version-history":[{"count":4,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10817\/revisions"}],"predecessor-version":[{"id":10869,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10817\/revisions\/10869"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}