-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (85 loc) · 2.97 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
name: Deployment (Container)
on:
push:
branches:
- master
- dev
# DKDK for manual run
workflow_dispatch:
env:
CACHE_KEY: node-deps
MONGODB_DB_NAME: gha-demo
jobs:
test:
# DKDK environment name is the one defined in the corresponding repo > Setting > Environment
environment: testing
# Runner
runs-on: ubuntu-latest
# DKDK add container using docker hub's image, node
# to have full control for environment
# by having container, jobs are running at docker container, not at ubuntu-latest
# container:
# image: node:20
env:
# DKDK for accessing mongodb cloud
# MONGODB_CONNECTION_PROTOCOL: mongodb+srv
# MONGODB_CLUSTER_ADDRESS: cluster0.ntrwp.mongodb.net
# MONGODB_USERNAME: ${{ secrets.MONGODB_USERNAME }}
# MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }}
# DKDK here, to access service container, mongodb in the following
# so al env should match with the container's env
# Note that this assumes that service container is running under node:20 container
MONGODB_CONNECTION_PROTOCOL: mongodb
# if not using node:20 container, then MONGODB_CLUSTER_ADDRESS should be changed
# e.g., MONGODB_CLUSTER_ADDRESS: 127.0.0.1:27017
# MONGODB_CLUSTER_ADDRESS: mongodb
MONGODB_CLUSTER_ADDRESS: 127.0.0.1:27017
MONGODB_USERNAME: root
MONGODB_PASSWORD: example
PORT: 8080
# DKDK add Service Containers: run a test DB at mongodb
services:
# DKDK service name, mongodb or anything
mongodb:
image: mongo
# DKDK if service container is not running under container (node:20), then ports should be defined
ports:
- 27017:27017
env:
# DKDK this is stated at Docker hub's mongodb document
MONTO_INITDB_ROOT_USERNAME: root
MONTO_INITDB_ROOT_PASSWORD: example
# PORT: 8080
steps:
- name: Get Code
uses: actions/checkout@v4
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci
- name: Run server
# DKDK does npx work???
# DKDK just in case, change $port to other variable
# DKDK for whatever reason, npx wait-on does not work...
# run: npm start & npx wait-on http://127.0.0.1:$PORT # requires MongoDB Atlas to accept requests from anywhere!
# run: npm start & npx wait-on http://127.0.0.1:8080
run: npm start
- name: Run tests
run: npm test
- name: Output information
run: |
echo "MONGODB_USERNAME: $MONGODB_USERNAME"
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- name: Output information
env:
PORT: 3000
run: |
echo "MONGODB_DB_NAME: $MONGODB_DB_NAME"
echo "MONGODB_USERNAME: $MONGODB_USERNAME"
echo "${{ env.PORT }}"