Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prod環境、GitHub Actionでbuild と deploy #212

Merged
merged 2 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,78 @@ on:
- v[0-9]+.[0-9]+.[0-9]+
paths-ignore:
- 'docs/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Publish Docker
uses: elgohr/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Registry
uses: docker/login-action@v1
with:
registry: registry.camph.net
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Check out
uses: actions/checkout@v2
- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
tags: registry.camph.net/relaym-server-prod:latest
context: .
file: ./docker/Dockerfile
- name: Notify to Slack
uses: craftech-io/slack-action@v1
with:
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
if: failure()
deploy:
name: deploy
runs-on: ubuntu-latest
needs: build
steps:
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.KONOE_SSH_KEY }}
name: id_rsa
known_hosts: ${{ secrets.KONOE_KNOWN_HOSTS }}
- name: Setup docker context
run: |
docker context create --default-stack-orchestrator=swarm --docker "host=ssh://${{ secrets.KONOE_SSH_USERNAME }}@${{ secrets.KONOE_SSH_HOST }}:${{ secrets.KONOE_SSH_PORT }}" konoe
docker context use konoe
- name: Login to Docker Registry
uses: docker/login-action@v1
with:
name: relaym-server-prod
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
registry: registry.camph.net
dockerfile: docker/Dockerfile
tags: "latest"
- name: Notify to Rundeck
uses: wei/[email protected]
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}
- name: Check out
uses: actions/checkout@v2
- name: deploy relaym-server-prod
run: |
docker pull registry.camph.net/relaym-server-prod:latest
docker-compose --context konoe -f docker/docker-compose.deps.base.yml -f docker/docker-compose.deps.prod.yml -p prod up -d
docker-compose --context konoe -f docker/docker-compose.base.yml -f docker/docker-compose.prod.yml -p prod stop
docker-compose --context konoe -f docker/docker-compose.base.yml -f docker/docker-compose.prod.yml -p prod up -d
env:
ENV: ${{ secrets.PROD_ENV }}
DB_DATABASE: ${{ secrets.PROD_DB_DATABASE }}
DB_USER: ${{ secrets.PROD_DB_USER }}
DB_PASSWORD: ${{ secrets.PROD_DB_PASSWORD }}
DB_ROOT_PASSWORD: ${{ secrets.PROD_DB_ROOT_PASSWORD }}
DB_HOST: ${{ secrets.PROD_DB_HOST }}
DB_PORT: ${{ secrets.PROD_DB_PORT }}
SPOTIFY_REDIRECT_URL: ${{ secrets.PROD_SPOTIFY_REDIRECT_URL }}
PORT: ${{ secrets.PROD_PORT }}
SPOTIFY_CLIENT_ID: ${{ secrets.PROD_SPOTIFY_CLIENT_ID }}
SPOTIFY_CLIENT_SECRET: ${{ secrets.PROD_SPOTIFY_CLIENT_SECRET }}
CORS_ALLOW_ORIGIN: ${{ secrets.PROD_CORS_ALLOW_ORIGIN }}
FRONTEND_URL: ${{ secrets.PROD_FRONTEND_URL }}
- name: Notify to Slack
uses: craftech-io/slack-action@v1
with:
args: https://${{ secrets.RUNDECK_DOMAIN }}/api/1/job/${{ secrets.RUNDECK_JOB_ID_PROD }}/run?authtoken=${{ secrets.RUNDECK_TOKEN }} -X POST
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,3 @@ run-db-local:
generate:
go generate ./...

.PHONY: deploy-prod
deploy-prod:
docker pull registry.camph.net/relaym-server-prod:latest
$(ENV_PROD) docker-compose -f docker/docker-compose.deps.base.yml -f docker/docker-compose.deps.prod.yml -p prod up -d
$(ENV_PROD) ENV_FILE=$(ENV_PROD_FILE) docker-compose -f docker/docker-compose.base.yml -f docker/docker-compose.prod.yml -p prod stop
$(ENV_PROD) ENV_FILE=$(ENV_PROD_FILE) docker-compose -f docker/docker-compose.base.yml -f docker/docker-compose.prod.yml -p prod up -d