Skip to content

Commit 85da770

Browse files
authored
Merge pull request #170 from DefangLabs/starter-sample
Starter sample
2 parents 7fdd53b + b288b12 commit 85da770

File tree

15 files changed

+1067
-0
lines changed

15 files changed

+1067
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
Samples to show you how to develop, deploy, and debug cloud applications with Defang.
44

55
Browse through the [./samples](./samples) directory, or search and browse in the [docs](https://docs.defang.io/docs/samples).
6+
7+
## Adding Samples
8+
9+
To start working on a new sample, run `. ./scripts/new-sample.sh` from the root of the repository. This will create a new sample directory, with some basic scaffolding to get you started. Look for `#REMOVE_ME_AFTER_EDITING` in your new project to look for things that you should probably be changing/checking per sample. Feel free to remove files, like `compose.dev.yaml` if they aren't necessary for your sample.

scripts/check-sample-files.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,13 @@ for dir in ./samples/*/; do
2222
echo " - [ ] add 'Languages:' to README.md in ${dir}"
2323
fi
2424
fi
25+
26+
# Check for #REMOVE_ME_AFTER_EDITING
27+
matches=$(grep -rnH "#REMOVE_ME_AFTER_EDITING" $dir* | cut -d: -f1,2)
28+
29+
if [ -n "$matches" ]; then
30+
echo "$matches" | while read -r line; do
31+
echo " - [ ] $line contains #REMOVE_ME_AFTER_EDITING... did you forget to edit this section?"
32+
done
33+
fi
2534
done

scripts/new-sample.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
while true; do
4+
# prompt for a directory name for the sample (should be kebab-case)
5+
printf "Enter the name of the sample (kebab-case): "
6+
read -r sample_name
7+
8+
# make sure it's actually kebab-case
9+
if [[ ! "$sample_name" =~ ^[a-z0-9-]+$ ]]; then
10+
echo "Sample name must be kebab-case"
11+
continue
12+
fi
13+
14+
# check if dir exists in the samples directory
15+
if [ -d "samples/$sample_name" ]; then
16+
echo "Sample already exists"
17+
continue
18+
fi
19+
20+
# if we reach here, the name is valid and the directory does not exist
21+
break
22+
done
23+
24+
# copy starter-sample to new sample directory
25+
cp -r starter-sample "samples/$sample_name"
26+
27+
# party time
28+
echo "Sample created at samples/$sample_name"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Note: universal image is not compatible with the devcontainer tools.
2+
# we use the typescript-node image instead here but should switch out per
3+
# project requirements. #REMOVE_ME_AFTER_EDITING
4+
5+
# FROM mcr.microsoft.com/devcontainers/go:1.22-bookworm
6+
# FROM mcr.microsoft.com/devcontainers/python:3.12-bookworm
7+
# FROM mcr.microsoft.com/devcontainers/php:8.3-bookworm
8+
# FROM mcr.microsoft.com/devcontainers/ruby:3.2-bookworm
9+
# FROM mcr.microsoft.com/devcontainers/java:11-bookworm
10+
# FROM mcr.microsoft.com/devcontainers/rust:1-bookworm
11+
FROM mcr.microsoft.com/devcontainers/typescript-node:22-bookworm
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"build": {
3+
"dockerfile": "Dockerfile",
4+
"context": ".."
5+
},
6+
"features": {
7+
"ghcr.io/defanglabs/devcontainer-feature/defang-cli:1.0.4": {},
8+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
9+
}
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v4
18+
19+
- name: Deploy
20+
uses: DefangLabs/[email protected]

starter-sample/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Starter Sample #REMOVE_ME_AFTER_EDITING
2+
3+
This is a sample that shows the rough structure of an actual Defang sample. This top paragraph should give a bit of context about the project and what it does. The rest of the README should be a guide on how to use the sample. #REMOVE_ME_AFTER_EDITING
4+
5+
## Prerequisites
6+
7+
1. Download [Defang CLI](https://github.com/DefangLabs/defang)
8+
2. (Optional) If you are using [Defang BYOC](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) authenticated with your AWS account
9+
3. (Optional for local development) [Docker CLI](https://docs.docker.com/engine/install/)
10+
11+
## Development
12+
13+
To run the application locally, you can use the following command:
14+
15+
```bash
16+
# This might be `docker compose -f compose.dev.yaml up` depending on the project. #REMOVE_ME_AFTER_EDITING
17+
docker compose up
18+
```
19+
20+
## Deploying
21+
22+
1. Open the terminal and type `defang login`
23+
2. Use the [`defang config`](https://docs.defang.io/docs/concepts/compose#configuration) command to setup environment variables. #REMOVE_ME_AFTER_EDITING
24+
3. Type `defang compose up` in the CLI.
25+
4. Your app will be running within a few minutes.
26+
27+
---
28+
29+
Title: Sample Title #REMOVE_ME_AFTER_EDITING
30+
31+
Short Description: A short sentence or two describing the sample. #REMOVE_ME_AFTER_EDITING
32+
33+
Tags: Tags, That, Are, Not, Programming, Languages #REMOVE_ME_AFTER_EDITING
34+
35+
Languages: Programming, Languages, Used #REMOVE_ME_AFTER_EDITING

starter-sample/app/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#REMOVE_ME_AFTER_EDITING - This Dockerignore is for a basic node app. Modify as needed.
2+
node_modules
3+
npm-debug.log

starter-sample/app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#REMOVE_ME_AFTER_EDITING - This Dockerignore is for a basic node app. Modify as needed.
2+
node_modules

starter-sample/app/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# A sample dockerfile for a Node.js application.
2+
# Replace with an appropriate Dockerfile for your application.
3+
#REMOVE_ME_AFTER_EDITING
4+
5+
FROM node:20-bookworm-slim
6+
7+
WORKDIR /app
8+
9+
COPY package*.json ./
10+
11+
RUN npm ci
12+
13+
COPY . .
14+
15+
RUN npm run build
16+
17+
EXPOSE 3000
18+
19+
CMD ["npm", "start"]

0 commit comments

Comments
 (0)