Skip to content

Commit adbaac9

Browse files
Reorganize repository structure and add Docker build workflows
Co-authored-by: nithinmohantk <[email protected]>
1 parent c2dd628 commit adbaac9

File tree

645 files changed

+316
-55
lines changed

Some content is hidden

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

645 files changed

+316
-55
lines changed

.dockerignore

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Git
2+
.git
3+
.gitignore
4+
.github
5+
6+
# Documentation
7+
README.md
8+
*.md
9+
docs/
10+
11+
# IDE and editor files
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.swo
16+
*~
17+
18+
# OS files
19+
.DS_Store
20+
Thumbs.db
21+
22+
# Logs
23+
logs
24+
*.log
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*
28+
29+
# Dependencies
30+
node_modules/
31+
npm-debug.log*
32+
33+
# Build outputs
34+
dist/
35+
build/
36+
.next/
37+
38+
# Environment files
39+
.env
40+
.env.local
41+
.env.development.local
42+
.env.test.local
43+
.env.production.local
44+
45+
# Images and media (keep certificate images in root)
46+
images/
47+
*.png
48+
*.jpg
49+
*.jpeg
50+
*.gif
51+
*.svg
52+
!images/certificate.png
53+
54+
# Test files
55+
test/
56+
tests/
57+
__tests__/
58+
*.test.js
59+
*.spec.js
60+
61+
# Coverage
62+
coverage/
63+
64+
# Temporary files
65+
tmp/
66+
temp/
67+
68+
# Other project artifacts
69+
*.tar.gz
70+
*.zip
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
branches: [ master, main, develop ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ master, main, develop ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
strategy:
22+
matrix:
23+
project:
24+
- name: image-filter-udagram
25+
path: src/project/image-filter-udagram-app
26+
- name: udacity-c2-frontend
27+
path: src/project/c2-microservices-v1/udacity-c2-frontend
28+
- name: udacity-c2-restapi-feed
29+
path: src/project/c2-microservices-v1/udacity-c2-restapi-feed
30+
- name: udacity-c2-restapi-user
31+
path: src/project/c2-microservices-v1/udacity-c2-restapi-user
32+
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Log in to Container Registry
41+
if: github.event_name != 'pull_request'
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ${{ env.REGISTRY }}
45+
username: ${{ github.actor }}
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Extract metadata
49+
id: meta
50+
uses: docker/metadata-action@v5
51+
with:
52+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.project.name }}
53+
tags: |
54+
type=ref,event=branch
55+
type=ref,event=pr
56+
type=semver,pattern={{version}}
57+
type=semver,pattern={{major}}.{{minor}}
58+
type=sha,prefix={{branch}}-
59+
labels: |
60+
org.opencontainers.image.title=${{ matrix.project.name }}
61+
org.opencontainers.image.description=Udacity AWS Developer Project - ${{ matrix.project.name }}
62+
63+
- name: Check if project has package.json
64+
id: check-project
65+
run: |
66+
if [ -f "${{ matrix.project.path }}/package.json" ]; then
67+
echo "has_package=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "has_package=false" >> $GITHUB_OUTPUT
70+
fi
71+
72+
- name: Build and push Docker image
73+
if: steps.check-project.outputs.has_package == 'true'
74+
uses: docker/build-push-action@v5
75+
with:
76+
context: .
77+
file: ./Dockerfile
78+
build-args: |
79+
PROJECT_PATH=${{ matrix.project.path }}
80+
push: ${{ github.event_name != 'pull_request' }}
81+
tags: ${{ steps.meta.outputs.tags }}
82+
labels: ${{ steps.meta.outputs.labels }}
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max
85+
86+
build-individual-dockerfiles:
87+
runs-on: ubuntu-latest
88+
permissions:
89+
contents: read
90+
packages: write
91+
92+
strategy:
93+
matrix:
94+
project:
95+
- name: c2-frontend-ionic
96+
dockerfile: src/project/c2-microservices-v1/udacity-c2-frontend/Dockerfile
97+
context: src/project/c2-microservices-v1/udacity-c2-frontend
98+
- name: c2-restapi-feed-individual
99+
dockerfile: src/project/c2-microservices-v1/udacity-c2-restapi-feed/Dockerfile
100+
context: src/project/c2-microservices-v1/udacity-c2-restapi-feed
101+
- name: c2-restapi-user-individual
102+
dockerfile: src/project/c2-microservices-v1/udacity-c2-restapi-user/Dockerfile
103+
context: src/project/c2-microservices-v1/udacity-c2-restapi-user
104+
105+
steps:
106+
- name: Checkout repository
107+
uses: actions/checkout@v4
108+
109+
- name: Set up Docker Buildx
110+
uses: docker/setup-buildx-action@v3
111+
112+
- name: Log in to Container Registry
113+
if: github.event_name != 'pull_request'
114+
uses: docker/login-action@v3
115+
with:
116+
registry: ${{ env.REGISTRY }}
117+
username: ${{ github.actor }}
118+
password: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Extract metadata
121+
id: meta
122+
uses: docker/metadata-action@v5
123+
with:
124+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.project.name }}
125+
tags: |
126+
type=ref,event=branch
127+
type=ref,event=pr
128+
type=semver,pattern={{version}}
129+
type=semver,pattern={{major}}.{{minor}}
130+
type=sha,prefix={{branch}}-
131+
132+
- name: Check if Dockerfile exists
133+
id: check-dockerfile
134+
run: |
135+
if [ -f "${{ matrix.project.dockerfile }}" ]; then
136+
echo "has_dockerfile=true" >> $GITHUB_OUTPUT
137+
else
138+
echo "has_dockerfile=false" >> $GITHUB_OUTPUT
139+
fi
140+
141+
- name: Build and push Docker image
142+
if: steps.check-dockerfile.outputs.has_dockerfile == 'true'
143+
uses: docker/build-push-action@v5
144+
with:
145+
context: ${{ matrix.project.context }}
146+
file: ${{ matrix.project.dockerfile }}
147+
push: ${{ github.event_name != 'pull_request' }}
148+
tags: ${{ steps.meta.outputs.tags }}
149+
labels: ${{ steps.meta.outputs.labels }}
150+
cache-from: type=gha
151+
cache-to: type=gha,mode=max

.github/workflows/project-c2-udagram.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
uses: actions/setup-node@v1
2525
with:
2626
node-version: ${{ matrix.node-version }}
27-
- run: cd project/image-filter-udagram-app/
28-
- run: cd project/image-filter-udagram-app/ && npm ci
29-
- run: cd project/image-filter-udagram-app/ && npm run build --if-present
30-
#- run: cd exercises/udacity-c2-restapi/ && npm test
27+
- run: cd src/project/image-filter-udagram-app/
28+
- run: cd src/project/image-filter-udagram-app/ && npm ci
29+
- run: cd src/project/image-filter-udagram-app/ && npm run build --if-present
30+
#- run: cd src/exercises/udacity-c2-restapi/ && npm test
3131
env:
3232
CI: true

.github/workflows/udacity-c2-basic-server.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
uses: actions/setup-node@v1
2525
with:
2626
node-version: ${{ matrix.node-version }}
27-
- run: cd exercises/udacity-c2-basic-server/
28-
- run: cd exercises/udacity-c2-basic-server/ && npm ci
29-
- run: cd exercises/udacity-c2-basic-server/ && npm run build --if-present
30-
# - run: cd exercises/udacity-c2-basic-server/ && npm test
27+
- run: cd src/exercises/udacity-c2-basic-server/
28+
- run: cd src/exercises/udacity-c2-basic-server/ && npm ci
29+
- run: cd src/exercises/udacity-c2-basic-server/ && npm run build --if-present
30+
# - run: cd src/exercises/udacity-c2-basic-server/ && npm test
3131
env:
3232
CI: true

.github/workflows/udacity-c2-frontend.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
uses: actions/setup-node@v1
2525
with:
2626
node-version: ${{ matrix.node-version }}
27-
- run: cd exercises/udacity-c2-frontend/
28-
- run: cd exercises/udacity-c2-frontend/ && npm ci
29-
- run: cd exercises/udacity-c2-frontend/ && npm run build --if-present
30-
# - run: cd exercises/udacity-c2-frontend/ && npm test
27+
- run: cd src/exercises/udacity-c2-frontend/
28+
- run: cd src/exercises/udacity-c2-frontend/ && npm ci
29+
- run: cd src/exercises/udacity-c2-frontend/ && npm run build --if-present
30+
# - run: cd src/exercises/udacity-c2-frontend/ && npm test
3131
env:
3232
CI: true

.github/workflows/udacity-c2-restapi.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
uses: actions/setup-node@v1
2525
with:
2626
node-version: ${{ matrix.node-version }}
27-
- run: cd exercises/udacity-c2-restapi/
28-
- run: cd exercises/udacity-c2-restapi/ && npm ci
29-
- run: cd exercises/udacity-c2-restapi/ && npm run build --if-present
30-
#- run: cd exercises/udacity-c2-restapi/ && npm test
27+
- run: cd src/exercises/udacity-c2-restapi/
28+
- run: cd src/exercises/udacity-c2-restapi/ && npm ci
29+
- run: cd src/exercises/udacity-c2-restapi/ && npm run build --if-present
30+
#- run: cd src/exercises/udacity-c2-restapi/ && npm test
3131
env:
3232
CI: true

Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Multi-stage Dockerfile for building and serving Udacity AWS Developer projects
2+
# This Dockerfile can build any of the Node.js projects in the src directory
3+
4+
ARG PROJECT_PATH=src/project/image-filter-udagram-app
5+
ARG NODE_VERSION=18.20.3
6+
7+
# Build stage
8+
FROM node:${NODE_VERSION}-slim AS builder
9+
10+
# Install build dependencies
11+
RUN apt-get update && apt-get install -y \
12+
git \
13+
python3 \
14+
make \
15+
g++ \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Set working directory
19+
WORKDIR /usr/src/app
20+
21+
# Copy the entire src directory
22+
COPY src/ ./src/
23+
COPY package*.json ./
24+
COPY README.md LICENSE ./
25+
26+
# Set the project path as build argument
27+
ARG PROJECT_PATH
28+
ENV PROJECT_DIR=${PROJECT_PATH}
29+
30+
# Install dependencies for the specific project
31+
WORKDIR /usr/src/app/${PROJECT_DIR}
32+
RUN npm ci --only=production
33+
34+
# Production stage
35+
FROM node:${NODE_VERSION}-slim AS production
36+
37+
# Install runtime dependencies
38+
RUN apt-get update && apt-get install -y \
39+
dumb-init \
40+
&& rm -rf /var/lib/apt/lists/*
41+
42+
# Create non-root user
43+
RUN groupadd -r appuser && useradd -r -g appuser appuser
44+
45+
# Set working directory
46+
WORKDIR /usr/src/app
47+
48+
# Copy built application from builder stage
49+
ARG PROJECT_PATH
50+
COPY --from=builder --chown=appuser:appuser /usr/src/app/${PROJECT_PATH} ./
51+
52+
# Switch to non-root user
53+
USER appuser
54+
55+
# Expose port
56+
EXPOSE 8080
57+
58+
# Use dumb-init to handle signals properly
59+
ENTRYPOINT ["dumb-init", "--"]
60+
61+
# Default command
62+
CMD ["npm", "start"]

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ This repository contains my practical project works for **Udacity Cloud Develope
1111

1212
### Folder Structure
1313

14-
* **exercises** - contains sample works as part of the labs from the chapters.
15-
- - _udacity-c2-basic-server_ - [exercises/udacity-c2-basic-server](exercises/udacity-c2-basic-server)
16-
- - _udacity-c2-restapi_ - [exercises/udacity-c2-frontend](exercises/udacity-c2-frontend)
17-
- - _udacity-c2-frontend_ - [exercises/udacity-c2-restapi](exercises/udacity-c2-restapi)
18-
- - _c4-serverless-demos_ - [exercises/c4-demos-master](exercises/c4-demos-master)
19-
- - _c4-frontend-client_ - [exercises/c4-client-master](exercises/c4-client-master)
20-
* **project** - contains actual project work submitted as part of the assignments for the curriculam
21-
22-
- - Project 1: Static site_Upload_s3 - [project/staticsite_upload_s3](project/staticsite_upload_s3)
23-
- - Project 2: Image-filter-service (Udagram API) - [project/image-filter-udagram-app](project/image-filter-udagram-app)
24-
- - Project 3: GitHub Profile modification and review - [my-github-profile](https://github.com/nithinmohantk)
25-
- - Project 4: Refactor Udagram app into Microservices and Deploy - _In this project, you will reuse their existing Udagram application and convert and extend into a microservice architecture._ - [project/c2-microservices-v1](project/c2-microservices-v1)
26-
- - Project 5: Serverless - using serverless framework and AWS lambda functions - [project/c4-serverless-app](project/c4-serverless-app)
27-
- - Project 6: LinkedIn Profile modification and review - [my-linkedin-profile](https://linkedin.com/in/nithinmohantk)
28-
- - Project 7: Capstone Project - Document Manager [project/p6-docman-app](project/p6-docman-app)
14+
* **src/** - contains all source code organized by category
15+
* **exercises** - contains sample works as part of the labs from the chapters.
16+
- - _udacity-c2-basic-server_ - [src/exercises/udacity-c2-basic-server](src/exercises/udacity-c2-basic-server)
17+
- - _udacity-c2-restapi_ - [src/exercises/udacity-c2-frontend](src/exercises/udacity-c2-frontend)
18+
- - _udacity-c2-frontend_ - [src/exercises/udacity-c2-restapi](src/exercises/udacity-c2-restapi)
19+
- - _c4-serverless-demos_ - [src/exercises/c4-demos-master](src/exercises/c4-demos-master)
20+
- - _c4-frontend-client_ - [src/exercises/c4-client-master](src/exercises/c4-client-master)
21+
* **project** - contains actual project work submitted as part of the assignments for the curriculam
22+
- - Project 1: Static site_Upload_s3 - [src/project/staticsite_upload_s3](src/project/staticsite_upload_s3)
23+
- - Project 2: Image-filter-service (Udagram API) - [src/project/image-filter-udagram-app](src/project/image-filter-udagram-app)
24+
- - Project 3: GitHub Profile modification and review - [my-github-profile](https://github.com/nithinmohantk)
25+
- - Project 4: Refactor Udagram app into Microservices and Deploy - _In this project, you will reuse their existing Udagram application and convert and extend into a microservice architecture._ - [src/project/c2-microservices-v1](src/project/c2-microservices-v1)
26+
- - Project 5: Serverless - using serverless framework and AWS lambda functions - [src/project/c4-serverless-app](src/project/c4-serverless-app)
27+
- - Project 6: LinkedIn Profile modification and review - [my-linkedin-profile](https://linkedin.com/in/nithinmohantk)
28+
- - Project 7: Capstone Project - Document Manager [src/project/p6-docman-app](src/project/p6-docman-app)
29+
* **starter** - contains starter code templates
30+
* **ci-scripts** - contains CI/CD scripts and utilities
2931

3032
## Installation
3133
The samples and projects found in this repository are created using Visual Studio Code and Node.js/NPM/ExpressJS stack and it require certain global NPM components and project NPM components(project.json).

0 commit comments

Comments
 (0)