add deploy workflow
Some checks failed
deploy / main (push) Failing after 5s

This commit is contained in:
Nebel 2024-01-03 21:34:51 +09:00
parent 4238eede11
commit 80030a4dff
Signed by: nebel
GPG key ID: 79807D08C6EF6460
6 changed files with 47 additions and 29 deletions

View file

@ -1,29 +0,0 @@
# yaml-language-server: $schema=https://json.schemastore.org/drone.json
name: deploy
kind: pipeline
type: docker
node:
instance: system
trigger:
event:
- push
branch:
- main
steps:
- name: deploy
image: docker:23.0.6-cli-alpine3.17@sha256:53221a6781b9360dc2965112998cfd209034f2b8cdf98bdc314dfd740bb3c845
commands:
- mkdir -p /root/.ssh
- install -v -m 600 /home/ubuntu/.ssh/id_ed25519 /root/.ssh/id_ed25519
- ssh-keyscan beta.fogtype.com >> /root/.ssh/known_hosts
- docker context create --docker=host=ssh://ubuntu@beta.fogtype.com beta
- docker context use beta
- docker compose --project-name=beta up --build --detach
- docker compose --project-directory=example up --detach
volumes:
- name: ssh_key
path: /home/ubuntu/.ssh/id_ed25519
volumes:
- name: ssh_key
host:
path: /home/ubuntu/.ssh/id_ed25519

View file

@ -0,0 +1,19 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: deploy
on:
push:
branches:
- main
jobs:
main:
runs-on: self-hosted
steps:
- run: install -m 700 -d ~/.ssh
- run: install -m 600 <(echo '${{ secrets.KNOWN_HOSTS }}') ~/.ssh/known_hosts
- # "error in libcrypto" になるので CR を除去して回避
run: install -m 600 <(echo '${{ secrets.DEPLOY_KEY }}' | tr -d '\r') ~/.ssh/id_ed25519
- run: apk add nodejs
- uses: actions/checkout@v3
- run: apk add make docker-cli-compose
- run: make setup
- run: make deploy

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.deploy_key
.deploy_key.pub

13
Makefile Normal file
View file

@ -0,0 +1,13 @@
.PHONY: setup
setup:
docker context create --docker=host=ssh://ubuntu@beta.fogtype.com beta
.PHONY: deploy
deploy: export DOCKER_CONTEXT := beta
deploy:
docker compose up --detach --remove-orphans --build
.deploy_key:
ssh-keygen -t ed25519 -f .deploy_key
ssh-copy-id -i .deploy_key.pub ubuntu@beta.fogtype.com
ssh-keyscan -t ed25519 -H beta.fogtype.com

View file

@ -30,3 +30,15 @@ ansible-playbook setup.yml
```
詳しい構成は [setup.yml](setup.yml) を参照
## Registration
```
$ make .deploy_key
```
secrets.KNOWN_HOSTS
: SSH known_hosts file
secrets.DEPLOY_KEY
: SSH identity file

View file

@ -1,3 +1,4 @@
name: beta
services:
caddy:
image: git.fogtype.com/nebel/caddy-docker-proxy