Skip to content

Commit bdefefe

Browse files
authored
feat: deploy action (#40)
1 parent 365ecf5 commit bdefefe

File tree

7 files changed

+176
-1
lines changed

7 files changed

+176
-1
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.github/workflows/cd.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
release:
9+
types:
10+
- released
11+
- prereleased
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
image-push:
19+
uses: ./.github/workflows/image-push.yml
20+
with:
21+
project: docs
22+
secrets: inherit
23+
24+
upgrade-server:
25+
needs:
26+
- image-push
27+
uses: coscene-io/cicd-templates/.github/workflows/sub-chart-upgrade.yml@main
28+
with:
29+
deployment-name: coscene-docs
30+
secrets: inherit

.github/workflows/image-push.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Push image build by pnpm 16g
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
project:
7+
description: 'the name of project to be built and the corresponding image'
8+
required: true
9+
type: string
10+
11+
outputs:
12+
tag:
13+
value: ${{ jobs.build.outputs.tag }}
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
environment: azure-dev-east-us
19+
env:
20+
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
21+
BUF_BUILD_TOKEN: ${{ secrets.BUF_BUILD_TOKEN }}
22+
GH_PACKAGES_ORG_TOKEN: ${{ secrets.GH_PACKAGES_ORG_TOKEN }}
23+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
24+
outputs:
25+
tag: ${{ steps.build-and-push.outputs.TAG }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
- name: Setup pnpm
30+
uses: pnpm/action-setup@v2
31+
with:
32+
version: 8
33+
- name: Setup Node env
34+
uses: actions/setup-node@v3
35+
with:
36+
node-version: 18
37+
cache: 'pnpm'
38+
- name: Install Dependencies
39+
run: pnpm install
40+
- name: Build
41+
run: pnpm run build
42+
43+
- name: Set up CD tools
44+
uses: coscene-io/setup-cd-tools@v2.0.1
45+
env:
46+
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
47+
with:
48+
skaffold: '2.3.1'
49+
- name: ACR login
50+
uses: docker/login-action@v2
51+
with:
52+
registry: coseus.azurecr.io
53+
username: ${{ secrets.ACR_ADMIN_USERNAME }}
54+
password: ${{ secrets.ACR_ADMIN_PASSWORD }}
55+
- name: Set up buf netrc
56+
uses: extractions/netrc@v1
57+
with:
58+
machine: buf.build
59+
username: ${{ secrets.BUF_USERNAME }}
60+
password: ${{ secrets.BUF_TOKEN }}
61+
- name: Set up github netrc
62+
uses: extractions/netrc@v1
63+
with:
64+
machine: github.com
65+
username: ${{ secrets.GH_PACKAGES_ORG_USERNAME }}
66+
password: ${{ secrets.GH_PACKAGES_ORG_TOKEN }}
67+
- name: Set up Docker Buildx
68+
uses: docker/setup-buildx-action@v2
69+
- name: Docker build & push
70+
id: build-and-push
71+
run: |
72+
result=$(skaffold build --build-concurrency=0 -q | jq '.builds[0].tag')
73+
skaffold build --build-concurrency=0 -t latest
74+
echo $result
75+
withoutRegistry=${result#*:}
76+
echo $withoutRegistry
77+
withoutDigest=${withoutRegistry%@*}
78+
echo $withoutDigest
79+
echo "TAG=${withoutDigest}" >> $GITHUB_OUTPUT
80+
81+
cp-image-to-aliyun:
82+
needs:
83+
- build
84+
uses: coscene-io/cicd-templates/.github/workflows/cp-image-to-aliyun.yml@main
85+
with:
86+
project: ${{ inputs.project }}
87+
tag: ${{ needs.build.outputs.tag }}
88+
secrets: inherit
89+
90+
callout:
91+
needs:
92+
- build
93+
uses: coscene-io/cicd-templates/.github/workflows/image-callout.yml@main
94+
with:
95+
project: ${{ inputs.project }}
96+
tag: ${{ needs.build.outputs.tag }}
97+
secrets: inherit

Caddyfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:8080
2+
3+
file_server
4+
5+
try_files {path} /index.html

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# production environment
2+
FROM caddy:2.6.4-alpine
3+
WORKDIR /build
4+
5+
COPY /build ./
6+
COPY /Caddyfile ./
7+
8+
EXPOSE 8080
9+
CMD ["caddy", "run"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "coscene-docs",
2+
"name": "@coscene-io/docs",
33
"version": "1.0.0",
44
"author": "minico",
55
"scripts": {

skaffold.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# since skaffold v2.0.3
2+
apiVersion: skaffold/v4beta1
3+
kind: Config
4+
build:
5+
tagPolicy:
6+
# e.g: 2022-12-05_v22.48.0-8-g295c572a
7+
# e.g: 2022-12-05-78c7d2b
8+
customTemplate:
9+
template: '{{.FOO}}-{{.BAR}}'
10+
components:
11+
- name: FOO
12+
dateTime:
13+
format: '2006-01-02'
14+
timezone: 'UTC'
15+
- name: BAR
16+
gitCommit:
17+
ignoreChanges: true
18+
artifacts:
19+
# Will copy from Azure to AliCloud
20+
- image: coseus.azurecr.io/docs
21+
context: .
22+
docker:
23+
dockerfile: Dockerfile
24+
buildArgs:
25+
GH_PACKAGES_ORG_TOKEN: '{{.GH_PACKAGES_ORG_TOKEN}}'
26+
local:
27+
useBuildkit: true
28+
profiles:
29+
- name: local
30+
build:
31+
local:
32+
push: false
33+
useBuildkit: false

0 commit comments

Comments
 (0)