Skip to content

Commit

Permalink
デプロイを試してみる
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Oct 20, 2024
1 parent c1a7286 commit cd91486
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/deploy-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ jobs:
run: python3 run.py package --env develop cattleshed
- name: Package kennel
run: python3 run.py package --env develop kennel
# - name: Deploy cattleshed to develop.wandbox.org
# run: |
# ./deploy.sh wandbox-ubuntu-24.04 cattleshed master
# - name: Deploy kennel to develop.wandbox.org
# run: |
# ./deploy.sh wandbox-ubuntu-24.04 kennel master
- name: Deploy cattleshed to develop.wandbox.org
run: |
python3 run.py deploy wandbox-ubuntu-24.04 cattleshed --env develop
- name: Deploy kennel to develop.wandbox.org
run: |
python3 run.py deploy wandbox-ubuntu-24.04 kennel --env develop
- uses: actions/setup-node@v2
with:
node-version: '16'
Expand All @@ -68,11 +68,11 @@ jobs:
set -ex
npm install
npm run build
# - name: Publish canine
# working-directory: canine
# env:
# CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
# run: |
# set -ex
# npm install -g @cloudflare/wrangler
# npm run deploy:dev
- name: Publish canine
working-directory: canine
env:
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
run: |
set -ex
npm install -g @cloudflare/wrangler
npm run deploy:dev
12 changes: 6 additions & 6 deletions .github/workflows/deploy-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ jobs:
run: python3 run.py package --env master cattleshed
- name: Package kennel
run: python3 run.py package --env master kennel
# - name: Deploy cattleshed to wandbox.org
# run: |
# ./deploy.sh wandbox-ubuntu-24.04 cattleshed master
# - name: Deploy kennel to wandbox.org
# run: |
# ./deploy.sh wandbox-ubuntu-24.04 kennel master
- name: Deploy cattleshed to wandbox.org
run: |
python3 run.py deploy wandbox-ubuntu-24.04 cattleshed --env master
- name: Deploy kennel to wandbox.org
run: |
python3 run.py deploy wandbox-ubuntu-24.04 kennel --env master
- uses: actions/setup-node@v2
with:
node-version: '16'
Expand Down
41 changes: 41 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,41 @@ def do_package(debug: bool, target: str, env: str, prefix: str):
rm_rf(os.path.join(prefix, f"{target}-{env}"))


def do_deploy(remote: str, target: str, env: str):
package_dir = os.path.join(BASE_DIR, "_package")

cmd(
[
"scp",
os.path.join(package_dir, f"{target}-{env}.tar.gz"),
f"{remote}:/tmp/{target}-{env}.tar.gz",
]
)
remote_command = f"""
set -ex
mkdir -p /opt/wandbox-data/release
pushd /opt/wandbox-data/release
tar xf /tmp/{target}-{env}.tar.gz
rm /tmp/{target}-{env}.tar.gz
pushd {target}-{env}
if [ "{target}" = "cattleshed" ]; then
setcap cap_sys_admin,cap_chown,cap_setuid,cap_setgid,cap_sys_chroot,cap_mknod,cap_net_admin=p bin/cattlegrid
fi
if [ "{target}" = "kennel" ]; then
# データ置き場を作る
mkdir -p var/lib/kennel
chown -R ubuntu:ubuntu var/
fi
popd
popd
cp /opt/wandbox-data/release/{target}-{env}/etc/{target}.service /etc/systemd/system/{target}-{env}.service
systemctl enable {target}-{env}
systemctl restart {target}-{env}
"""
cmd(["ssh", remote, "/bin/bash", "-c", remote_command])


PACKAGE_PREFIX = "/opt/wandbox-data/release"


Expand All @@ -256,13 +291,19 @@ def main():
pp.add_argument("--env", choices=["master", "develop"], required=True)
pp.add_argument("--debug", action="store_true")
pp.add_argument("--prefix", default=PACKAGE_PREFIX)
dp = sp.add_parser("deploy")
dp.add_argument("remote")
dp.add_argument("target", choices=["kennel", "cattleshed"])
dp.add_argument("--env", choices=["master", "develop"], required=True)

args = parser.parse_args()

if args.op == "build":
do_build(debug=args.debug, target=args.target)
elif args.op == "package":
do_package(debug=args.debug, target=args.target, env=args.env, prefix=args.prefix)
elif args.op == "deploy":
do_deploy(remote=args.remote, target=args.target, env=args.env)


if __name__ == "__main__":
Expand Down

0 comments on commit cd91486

Please sign in to comment.