Skip to content

Commit c647208

Browse files
committed
Init project
1 parent 4612818 commit c647208

Some content is hidden

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

79 files changed

+7249
-1
lines changed

.github/workflows/build_docker.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build Docker Images
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
name: Run Java Tests
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
14+
- uses: actions/setup-java@v4
15+
with:
16+
java-version: '21'
17+
distribution: 'temurin'
18+
19+
- name: Setup Gradle
20+
uses: gradle/actions/setup-gradle@v4
21+
22+
- name: Build with Gradle
23+
run: cd server && ./gradlew build
24+
25+
build:
26+
name: Build Docker Images
27+
needs: test
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
service: [client, client-canary, server]
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Log in to the Container registry
39+
uses: docker/login-action@v3
40+
with:
41+
registry: ghcr.io
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
with:
48+
platforms: all
49+
50+
- name: Install Docker Buildx
51+
id: buildx
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Extract metadata (tags, labels) for Docker
55+
id: meta
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ghcr.io/${{ github.repository }}/${{ matrix.service }}
59+
tags: |
60+
type=raw,value=latest,enable={{is_default_branch}}
61+
type=ref,event=branch
62+
type=ref,event=pr
63+
64+
- name: Build and push Docker Image
65+
uses: docker/build-push-action@v5
66+
with:
67+
platforms: linux/amd64,linux/arm64
68+
context: ./${{ matrix.service }}
69+
file: ./${{ matrix.service }}/Dockerfile
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy Docker Images
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
environment:
10+
name: AWS
11+
url: 'https://client.${{ vars.EC2_PUBLIC_IP }}.nip.io'
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
16+
- name: Copy Docker Compose File From Repo to VM Host
17+
uses: appleboy/scp-action@v0.1.7
18+
with:
19+
host: ${{ vars.EC2_PUBLIC_IP }}
20+
username: ${{ vars.AWS_EC2_USER }}
21+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
22+
source: "./compose.aws.yml"
23+
target: /home/${{ vars.AWS_EC2_USER }}
24+
25+
- name: SSH to VM and Create .env.prod
26+
uses: appleboy/ssh-action@v1.0.3
27+
with:
28+
host: ${{ vars.EC2_PUBLIC_IP }}
29+
username: ${{ vars.AWS_EC2_USER }}
30+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
31+
script: |
32+
rm .env.prod
33+
touch .env.prod
34+
echo "CLIENT_HOST=client.${{ vars.EC2_PUBLIC_IP }}.nip.io" >> .env.prod
35+
echo "SERVER_HOST=api.${{ vars.EC2_PUBLIC_IP }}.nip.io" >> .env.prod
36+
echo "PUBLIC_API_URL=https://api.${{ vars.EC2_PUBLIC_IP }}.nip.io/api" >> .env.prod
37+
38+
- name: SSH to VM and Execute Docker-Compose Up
39+
uses: appleboy/ssh-action@v1.0.3
40+
with:
41+
host: ${{ vars.EC2_PUBLIC_IP }}
42+
username: ${{ vars.AWS_EC2_USER }}
43+
key: ${{ secrets.AWS_EC2_PRIVATE_KEY }}
44+
script: |
45+
echo "Logging into Docker registry..."
46+
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
47+
echo "Starting Docker Compose..."
48+
docker compose -f compose.aws.yml --env-file=.env.prod up --pull=always -d

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# user-specific
2+
.idea/workspace.xml
3+
.idea/tasks.xml
4+
.idea/vcs.xml
5+
.idea/misc.xml
6+
.idea/modules.xml
7+
.idea/w06-template.iml

README.md

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,145 @@
1-
# w06-template
1+
# DevOps W06 In-Class Exercise Template
2+
3+
This repository contains a full-stack application with a SvelteKit client and a Spring Boot server. It demonstrates modern web application architecture and DevOps practices.
4+
5+
## Project Overview
6+
7+
This project includes:
8+
- **Client**: SvelteKit with TypeScript, TailwindCSS, and reusable UI components.
9+
- **Server**: Spring Boot Java application with RESTful APIs.
10+
- **DevOps**: Dockerized services, CI/CD pipelines, and production-ready deployment configurations.
11+
12+
## Prerequisites
13+
14+
- Node.js (v22 or later)
15+
- Java JDK 21+
16+
- Gradle
17+
- Docker and Docker Compose
18+
- Git
19+
20+
## Setup Instructions
21+
22+
### Clone the Repository
23+
24+
```bash
25+
git clone https://github.com/yourusername/w06-template.git
26+
cd w06-template
27+
```
28+
29+
### Client Setup
30+
31+
1. Navigate to the `client` directory:
32+
```bash
33+
cd client
34+
```
35+
2. Install dependencies:
36+
```bash
37+
npm install
38+
```
39+
40+
### Server Setup
41+
42+
1. Navigate to the `server` directory:
43+
```bash
44+
cd server
45+
```
46+
2. Build the project:
47+
```bash
48+
./gradlew build
49+
```
50+
51+
## Running the Application
52+
53+
### Start the Client/Client Canary
54+
55+
```bash
56+
cd client
57+
npm run dev
58+
```
59+
The client will be available at [http://localhost:3000](http://localhost:3000).
60+
61+
### Start the Server
62+
63+
```bash
64+
cd server
65+
./gradlew bootRun
66+
```
67+
The server API will be available at [http://localhost:8080](http://localhost:8080).
68+
69+
## Development Workflow
70+
71+
### Client Development
72+
73+
- Built with SvelteKit and TypeScript for a modern, reactive UI.
74+
- TailwindCSS for styling.
75+
- Components and routes are organized in the `src` directory.
76+
77+
### Server Development
78+
79+
- Built with Spring Boot for scalable and maintainable server services.
80+
- Gradle is used for dependency management and building.
81+
- Source code is in the `src/main/java` directory.
82+
- Tests are in the `src/test/java` directory.
83+
84+
## Building for Production
85+
86+
### Client Build
87+
88+
```bash
89+
cd client
90+
npm run build
91+
```
92+
93+
### Server Build
94+
95+
```bash
96+
cd server
97+
./gradlew clean build
98+
```
99+
100+
## Dockerized Deployment
101+
102+
The project includes Docker configurations for containerized deployment.
103+
104+
### Build and Run with Docker Compose
105+
106+
1. Build and start the services:
107+
```bash
108+
docker compose up --build
109+
```
110+
2. Access the application:
111+
- Client: [http://localhost:3000](http://localhost:3000)
112+
- Client Canary: [http://localhost:3001](http://localhost:3001)
113+
- Server: [http://localhost:8080](http://localhost:8080)
114+
115+
## CI/CD Pipeline
116+
117+
The project includes GitHub Actions workflows for:
118+
- **Building Docker Images**: Automatically builds and pushes Docker images to GitHub Container Registry.
119+
- **Deploying Docker Images**: Deploys the application to a production environment using Docker Compose.
120+
121+
## Project Structure
122+
123+
```
124+
├── client/ # SvelteKit client
125+
│ ├── src/ # Source code
126+
│ ├── public/ # Static assets
127+
│ └── package.json # Client dependencies
128+
129+
├── client-canary/ # SvelteKit client with the changes to the original client
130+
│ ├── src/ # Source code
131+
│ ├── public/ # Static assets
132+
│ └── package.json # Client dependencies
133+
|
134+
├── server/ # Spring Boot server
135+
│ ├── src/ # Source code
136+
│ ├── build.gradle # Gradle build file
137+
│ └── Dockerfile # Server Dockerfile
138+
139+
├── compose.yml # Docker Compose for local development
140+
└── .github/workflows/ # CI/CD workflows
141+
```
142+
143+
## License
144+
145+
This project is licensed under the MIT License.

client-canary/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
npm-debug.log
3+
Dockerfile
4+
.dockerignore
5+
.git
6+
.gitignore
7+
README.md
8+
.env

client-canary/.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
node_modules
2+
3+
# Output
4+
.output
5+
.vercel
6+
.netlify
7+
.wrangler
8+
/.svelte-kit
9+
/build
10+
11+
# OS
12+
.DS_Store
13+
Thumbs.db
14+
15+
# Env
16+
.env
17+
.env.*
18+
!.env.example
19+
!.env.test
20+
21+
# Vite
22+
vite.config.js.timestamp-*
23+
vite.config.ts.timestamp-*

client-canary/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

client-canary/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Use a Node.js Alpine image for the builder stage
2+
FROM node:22-alpine AS builder
3+
WORKDIR /app
4+
COPY package*.json ./
5+
RUN npm ci
6+
COPY . .
7+
RUN npm run build
8+
RUN npm prune --production
9+
10+
# Use a distroless image for the final stage
11+
FROM gcr.io/distroless/nodejs22-debian12
12+
WORKDIR /app
13+
COPY --from=builder /app/build build/
14+
COPY --from=builder /app/node_modules node_modules/
15+
COPY package.json .
16+
EXPOSE 3000
17+
ENV NODE_ENV=production
18+
CMD ["build/index.js"]

client-canary/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# sv
2+
3+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
4+
5+
## Creating a project
6+
7+
If you're seeing this, you've probably already done this step. Congrats!
8+
9+
```bash
10+
# create a new project in the current directory
11+
npx sv create
12+
13+
# create a new project in my-app
14+
npx sv create my-app
15+
```
16+
17+
## Developing
18+
19+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20+
21+
```bash
22+
npm run dev
23+
24+
# or start the server and open the app in a new browser tab
25+
npm run dev -- --open
26+
```
27+
28+
## Building
29+
30+
To create a production version of your app:
31+
32+
```bash
33+
npm run build
34+
```
35+
36+
You can preview the production build with `npm run preview`.
37+
38+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

0 commit comments

Comments
 (0)