-
Notifications
You must be signed in to change notification settings - Fork 2
148 lines (148 loc) · 5.24 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Deploy
on:
pull_request:
branches: [main]
workflow_dispatch:
jobs:
# deploy-package-next:
# runs-on: ubuntu-latest
# env:
# DOCKER_IMAGE: package
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# steps:
# - name: Check out the repo
# uses: actions/checkout@v2
# with:
# # NOTE(krishan711): need full history to calculate difference
# fetch-depth: 0
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
# - name: Build docker image
# uses: docker/build-push-action@v2
# with:
# context: .
# load: true
# cache-from: type=gha,scope=package
# cache-to: type=gha,mode=max,scope=package
# tags: ${{ env.DOCKER_IMAGE }}
# target: build
# - name: Calculate commit count since last tag
# id: vars
# run: echo ::set-output name=commit_count::$(git rev-list $(git describe --tags --abbrev=0)..HEAD --count)
# - name: Create .npmrc file
# run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
# - name: Publish next package to npm
# if: steps.vars.outputs.commit_count != '0'
# run: docker run -v $(pwd)/.npmrc:/root/.npmrc $DOCKER_IMAGE /bin/bash -c "npm run publish-next -- --next-version ${{ steps.vars.outputs.commit_count }}"
deploy-console-next:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE_CONSOLE: ghcr.io/${{ github.repository }}-console:next
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push console docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
cache-from: type=gha,scope=console
cache-to: type=gha,mode=max,scope=console
tags: ${{ env.DOCKER_IMAGE_CONSOLE }}
target: console
deploy-builder-api-next:
runs-on: ubuntu-latest
env:
DOCKER_IMAGE_BUILDER_API: ghcr.io/${{ github.repository }}-builder-api:next
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push builder-api docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
cache-from: type=gha,scope=builder-api
cache-to: type=gha,mode=max,scope=builder-api
tags: ${{ env.DOCKER_IMAGE_BUILDER_API }}
target: builder-api
run-console-next:
needs: deploy-console-next
runs-on: ubuntu-latest
env:
NAME: everypage-console-next
DOCKER_IMAGE: ghcr.io/${{ github.repository }}-console:next
steps:
- name: executing remote ssh commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.APIBOX_URL }}
username: ${{ secrets.APIBOX_USER }}
key: ${{ secrets.APIBOX_SSH_KEY }}
port: ${{ secrets.APIBOX_PORT }}
envs: DOCKER_IMAGE,NAME
script_stop: true
script: |
url="console-next.everypagehq.com"
docker pull ${DOCKER_IMAGE}
docker stop ${NAME} && docker rm ${NAME} || true
docker run \
--name ${NAME} \
--detach \
--publish-all \
--restart unless-stopped \
--env NAME=${NAME} \
--env VERSION=${VERSION} \
--env VIRTUAL_HOST=${url} \
--env LETSENCRYPT_HOST=${url} \
--env-file ~/.${NAME}.vars \
${DOCKER_IMAGE}
run-builder-api-next:
needs: deploy-builder-api-next
runs-on: ubuntu-latest
env:
NAME: everypage-builder-api-next
DOCKER_IMAGE: ghcr.io/${{ github.repository }}-builder-api:next
NETWORK: everypage-network
steps:
- name: executing remote ssh commands
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.WORKERBOX_URL }}
username: ${{ secrets.WORKERBOX_USER }}
key: ${{ secrets.WORKERBOX_SSH_KEY }}
port: ${{ secrets.WORKERBOX_PORT }}
envs: DOCKER_IMAGE,NAME,NETWORK
script_stop: true
script: |
docker network create ${NETWORK} || true
docker pull ${DOCKER_IMAGE}
docker stop ${NAME} && docker rm ${NAME} || true
docker run \
--name ${NAME} \
--detach \
--publish-all \
--restart unless-stopped \
--memory 768m \
--cpus 1.0 \
--net ${NETWORK} \
--env NAME=${NAME} \
--env VERSION=${VERSION} \
--env-file ~/.${NAME}.vars \
${DOCKER_IMAGE}