add mongo db container. #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deployment (Container) | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
env: | ||
CACHE_KEY: node-deps | ||
MONGODB_DB_NAME: gha-demo | ||
jobs: | ||
test: | ||
environment: testing | ||
runs-on: ubuntu-latest | ||
container: | ||
image: node:16 | ||
env: | ||
MONGODB_CONNECTION_PROTOCOL: mongodb | ||
# use the database from the service below. | ||
MONGODB_CLUSTER_ADDRESS: mongodb | ||
# We're using the mongdb server noted below. | ||
MONGODB_USERNAME: root | ||
MONGODB_PASSWORD: example | ||
PORT: 8080 | ||
services: | ||
mongodb: | ||
image: mongo | ||
env: | ||
# These are test credentials for the db running in the container, fine | ||
# to expose here. | ||
MONGO_INITDB_ROOT_USERNAME: root | ||
MONGO_INITDB_ROOT_PASSWORD: example | ||
ports: | ||
- 27017:27017 | ||
env: | ||
MONGO_INITDB_ROOT_USERNAME: ${{ secrets.MONGODB_USERNAME }} | ||
MONGO_INITDB_ROOT_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} | ||
MONGO_INITDB_DATABASE: ${{ env.MONGODB_DB_NAME }} | ||
steps: | ||
- name: Get Code | ||
uses: actions/checkout@v3 | ||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.npm | ||
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/package-lock.json') }} | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run server | ||
run: npm start & npx wait-on http://127.0.0.1:$PORT # requires MongoDB Atlas to accept requests from anywhere! | ||
- 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 }}" |