Skip to content

Commit cca972d

Browse files
committed
Restructured and added content
1 parent de07609 commit cca972d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+7256
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# startups-content
2-
Workshop and getting started content for organizations using GitHub for Startups
1+
# Pets workshop
2+
3+
This repository contains the project for both a guided workshop and the Modern DevOps with GitHub What The Hack. The project is a Next.js app that uses MongoDB for the database. The design is to be used as a walk-through of GitHub features, including [Codespaces](https://docs.github.com/en/codespaces/overview), [Actions](https://docs.github.com/en/actions/learn-github-actions) and [GitHub Advanced Security (GHAS)](https://docs.github.com/en/github/getting-started-with-github/about-github-advanced-security). You'll explore how to use these features to implement and improve your organization's DevOps processes.

config/main.bicep

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
@minLength(3)
2+
@maxLength(11)
3+
param namePrefix string
4+
5+
param location string = resourceGroup().location
6+
7+
resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2021-04-15' = {
8+
name: '${namePrefix}cosmos'
9+
kind: 'MongoDB'
10+
location: location
11+
properties: {
12+
consistencyPolicy: {
13+
defaultConsistencyLevel: 'Session'
14+
}
15+
locations: [
16+
{
17+
locationName: location
18+
failoverPriority: 0
19+
isZoneRedundant: false
20+
}
21+
]
22+
databaseAccountOfferType: 'Standard'
23+
enableAutomaticFailover: false
24+
enableMultipleWriteLocations: false
25+
apiProperties: {
26+
serverVersion: '4.0'
27+
}
28+
capabilities: [
29+
{
30+
name: 'EnableServerless'
31+
}
32+
]
33+
}
34+
35+
resource database 'mongodbDatabases' = {
36+
name: 'Pets'
37+
properties: {
38+
resource: {
39+
id: 'Pets'
40+
}
41+
}
42+
43+
resource list 'collections' = {
44+
name: 'PetList'
45+
properties: {
46+
resource: {
47+
id: 'PetList'
48+
shardKey: {
49+
_id: 'Hash'
50+
}
51+
indexes: [
52+
{
53+
key: {
54+
keys: [
55+
'_id'
56+
]
57+
}
58+
}
59+
]
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-12-01-preview' = {
67+
name: '${namePrefix}loganalytics'
68+
location: location
69+
properties: {
70+
sku: {
71+
name: 'PerGB2018'
72+
}
73+
}
74+
}
75+
76+
resource containerRegistry 'microsoft.containerregistry/registries@2021-12-01-preview' = {
77+
name: '${namePrefix}acr'
78+
location: location
79+
properties: {
80+
adminUserEnabled: true
81+
}
82+
sku: {
83+
name: 'Basic'
84+
}
85+
}
86+
87+
resource conatinerAppEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = {
88+
name: '${namePrefix}containerappenvironment'
89+
location: location
90+
properties: {
91+
appLogsConfiguration: {
92+
destination: 'log-analytics'
93+
logAnalyticsConfiguration: {
94+
customerId: logAnalytics.properties.customerId
95+
sharedKey: logAnalytics.listKeys().primarySharedKey
96+
}
97+
}
98+
}
99+
}
100+
101+
resource containerApp 'Microsoft.App/containerApps@2022-03-01' = {
102+
name: '${namePrefix}containerapp'
103+
location: location
104+
properties: {
105+
managedEnvironmentId: conatinerAppEnvironment.id
106+
configuration: {
107+
ingress: {
108+
external: true
109+
targetPort: 80
110+
allowInsecure: false
111+
traffic: [
112+
{
113+
latestRevision: true
114+
weight: 100
115+
}
116+
]
117+
}
118+
registries: [
119+
{
120+
server: containerRegistry.name
121+
username: containerRegistry.properties.loginServer
122+
passwordSecretRef: 'container-registry-password'
123+
}
124+
]
125+
secrets: [
126+
{
127+
name: 'container-registry-password'
128+
value: containerRegistry.listCredentials().passwords[0].value
129+
}
130+
{
131+
name: 'cosmosdb-connection-string'
132+
value: cosmos.listConnectionStrings().connectionStrings[0].connectionString
133+
}
134+
]
135+
}
136+
template: {
137+
containers: [
138+
{
139+
name: '${namePrefix}containerapp'
140+
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
141+
env: [
142+
{
143+
name: 'MONGODB_URI'
144+
secretRef: 'cosmosdb-connection-string'
145+
}
146+
]
147+
resources: {
148+
cpu: '0.5'
149+
memory: '1.0Gi'
150+
}
151+
}
152+
]
153+
}
154+
}
155+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM mcr.microsoft.com/devcontainers/javascript-node:0-18
2+
3+
# Install MongoDB command line tools - though mongo-database-tools not available on arm64
4+
ARG MONGO_TOOLS_VERSION=6.0
5+
RUN . /etc/os-release \
6+
&& curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \
7+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian ${VERSION_CODENAME}/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \
8+
&& apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
&& apt-get install -y mongodb-mongosh \
10+
&& if [ "$(dpkg --print-architecture)" = "amd64" ]; then apt-get install -y mongodb-database-tools; fi \
11+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
12+
13+
# [Optional] Uncomment this section to install additional OS packages.
14+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
15+
# && apt-get -y install --no-install-recommends <your-package-list-here>
16+
17+
# [Optional] Uncomment if you want to install an additional version of node using nvm
18+
# ARG EXTRA_NODE_VERSION=10
19+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
20+
21+
# [Optional] Uncomment if you want to install more global node modules
22+
# RUN su node -c "npm install -g <your-package-list-here>"
23+
24+
25+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node-mongo
3+
{
4+
"name": "Node.js & Mongo DB",
5+
"dockerComposeFile": "docker-compose.yml",
6+
"service": "app",
7+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
8+
9+
// Features to add to the dev container. More info: https://containers.dev/features.
10+
// "features": {},
11+
12+
// Configure tool-specific properties.
13+
"customizations": {
14+
// Configure properties specific to VS Code.
15+
"vscode": {
16+
// Add the IDs of extensions you want installed when the container is created.
17+
"extensions": [
18+
"mongodb.mongodb-vscode"
19+
]
20+
}
21+
},
22+
"features": {
23+
"ghcr.io/devcontainers/features/azure-cli:1": {},
24+
"ghcr.io/devcontainers/features/github-cli:1": {}
25+
}
26+
27+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
28+
// "forwardPorts": [3000, 27017],
29+
30+
// Use 'postCreateCommand' to run commands after the container is created.
31+
// "postCreateCommand": "yarn install",
32+
33+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
34+
// "remoteUser": "root"
35+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
volumes:
9+
- ../..:/workspaces:cached
10+
11+
# Overrides default command so things don't shut down after the process ends.
12+
command: sleep infinity
13+
14+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
15+
network_mode: service:db
16+
17+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
18+
# (Adding the "ports" property to this file will not forward from a Codespace.)
19+
20+
db:
21+
image: mongo:latest
22+
restart: unless-stopped
23+
volumes:
24+
- mongodb-data:/data/db
25+
26+
# Uncomment to change startup options
27+
# environment:
28+
# MONGO_INITDB_ROOT_USERNAME: root
29+
# MONGO_INITDB_ROOT_PASSWORD: example
30+
# MONGO_INITDB_DATABASE: your-database-here
31+
32+
# Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally.
33+
# (Adding the "ports" property to this file will not forward from a Codespace.)
34+
35+
volumes:
36+
mongodb-data:

content/guided-workshop/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Running the in Codespaces
2+
3+
The repository can be configured with a [dev container](https://code.visualstudio.com/docs/remote/create-dev-container) which can be used with Codespaces. The container uses Docker Compose to combine the [Cypress](https://github.com/cypress-io/cypress-docker-images) image for web app dev and [MongoDB](https://www.mongodb.com/compatibility/docker) for the database.
4+
5+
To run the project in Codespaces:
6+
7+
1. Copy the **.devcontainer** folder to the root of the repository.
8+
1. Commit and push the changes to GitHub.
9+
1. Open the repository in GitHub, and create a [Codespaces secret](https://docs.github.com/en/codespaces/managing-your-codespaces/managing-encrypted-secrets-for-your-codespaces) to store the MongoDB connection string by:
10+
1. Selecting **Settings** > **Secrets and variables** > **Codespaces** > **New repository secret**.
11+
2. Set the name to **MONGODB_URI**
12+
3. Set the secret to **mongodb://localhost**
13+
4. Select **Add Secret**
14+
1. Select **Code** to return to the main page for the repository.
15+
1. To launch the repository, select **Code** > **Codespaces** > **Create codespace on main**.
16+
1. After the codespace is loaded, open a new terminal by selecting **Ctl** **`** on your keyboard.
17+
1. In the terminal, run the following to install the packages and start the server:
18+
```bash
19+
npm install
20+
npm run dev
21+
```
22+
1. Open the site by selecting **Open Browser** in the lower right corner of the Codespace window.

0 commit comments

Comments
 (0)