Skip to content

Commit 85d8566

Browse files
authored
Merge pull request #10 from agung-learns/feature/gatsby
[Gatsby] Initialize Project, Dockerize, Kubernetes and Github Workflow
2 parents 9a0d0af + 4355627 commit 85d8566

File tree

18 files changed

+27305
-0
lines changed

18 files changed

+27305
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Docker Implementation
55
* React
66
* [React](https://github.com/agung-learns/docker-implementation/tree/main/react/react-docker)
77
* [NextJS](https://github.com/agung-learns/docker-implementation/tree/main/react/nextjs-docker)
8+
* [Gatsby](https://github.com/agung-learns/docker-implementation/tree/main/react/gatsby-docker)
89
* Vue
910
* [NuxtJS](https://github.com/agung-learns/docker-implementation/tree/main/vue/nuxtjs-docker)
1011
* Angular

react/gatsby-docker/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.cache/
3+
4+
public
5+
6+
src/gatsby-types.d.ts

react/gatsby-docker/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GATSBY_BASE_URL=http://localhost:8000
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "CI"
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
SHA: ${{ github.sha }}
10+
GKE_CLUSTER: deploy-learn
11+
GKE_ZONE: asia-southeast1-b
12+
13+
jobs:
14+
build_push:
15+
name: "Build & Push Image"
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: "Login to Docker Hub"
22+
uses: docker/login-action@v2
23+
with:
24+
username: ${{ secrets.DOCKER_ID }}
25+
password: ${{ secrets.DOCKER_PASSWORD }}
26+
27+
- name: "Build & Push"
28+
run: |
29+
docker build -t agung96tm/gatsby-app:latest -t agung96tm/gatsby-app:$SHA -f Dockerfile .
30+
docker push agung96tm/gatsby-app:$SHA
31+
env:
32+
SHA: ${{ env.SHA }}
33+
34+
deploy:
35+
name: "Deploy to Cluster"
36+
runs-on: ubuntu-latest
37+
needs: [ build_push ]
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
42+
- id: 'auth'
43+
uses: 'google-github-actions/auth@v2'
44+
with:
45+
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'
46+
47+
- name: 'Set up GKE credentials'
48+
uses: 'google-github-actions/get-gke-credentials@v2'
49+
with:
50+
cluster_name: ${{ env.GKE_CLUSTER }}
51+
location: ${{ env.GKE_ZONE }}
52+
53+
- name: 'Deploy to GKE'
54+
run: |
55+
kubectl apply -f deploy/k8s
56+
kubectl set image deployment/app-deployment app=agung96tm/gatsby-app:$SHA
57+
env:
58+
SHA: ${{ env.SHA }}

react/gatsby-docker/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
.cache/
3+
public
4+
src/gatsby-types.d.ts
5+
6+
.env

react/gatsby-docker/Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Stage 1: Install dependencies
2+
FROM node:20-alpine as deps
3+
4+
WORKDIR /app
5+
6+
COPY package*.json ./
7+
8+
# Install build tools and Python for native dependencies
9+
RUN apk add --no-cache python3 g++ make
10+
11+
RUN npm ci
12+
RUN npm install
13+
14+
15+
FROM node:20-alpine as development
16+
17+
ENV GATSBY_TELEMETRY_DISABLED 1
18+
19+
WORKDIR /app
20+
COPY --from=deps /app/node_modules ./node_modules
21+
COPY . .
22+
23+
24+
FROM node:20-alpine as build
25+
26+
WORKDIR /app
27+
COPY --from=deps /app/node_modules ./node_modules
28+
COPY . .
29+
30+
RUN npm run build
31+
32+
# Stage 4: Production environment
33+
FROM nginx:1.27.0-alpine as production
34+
35+
COPY --from=build /app/public /usr/share/nginx/html
36+
EXPOSE 80
37+
38+
CMD ["nginx", "-g", "daemon off;"]

react/gatsby-docker/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Gatsby with Docker
2+
================================
3+
4+
5+
### How to Run
6+
7+
#### Docker
8+
```shell
9+
cp .env.example .env
10+
docker compose up --build
11+
```
12+
13+
#### Kubernetes
14+
```shell
15+
kubectl apply -f deploy/k8s
16+
```
17+
18+
### Contributors
19+
<table>
20+
<tr>
21+
<td align="center">
22+
<a href="https://www.linkedin.com/in/agung96tm/">
23+
<img src="https://avatars.githubusercontent.com/u/1901484?v=4" width="100px;" alt=""/><br />
24+
<b>Agung Yuliyanto</b><br>
25+
</a>
26+
</td>
27+
</tr>
28+
</table>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: gatsby-deployment
5+
spec:
6+
replicas: 3
7+
selector:
8+
matchLabels:
9+
component: gatsby-app
10+
template:
11+
metadata:
12+
labels:
13+
component: gatsby-app
14+
containers:
15+
- name: app
16+
image: agung96tm/gatsby-app
17+
ports:
18+
- containerPort: 3000
19+
env:
20+
- name: GATSBY_BASE_URL
21+
value: 'https://www.linkedin.com/in/agung96tm'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: gatsby-service
5+
spec:
6+
type: ClusterIP
7+
selector:
8+
component: gatsby-app
9+
ports:
10+
- port: 80
11+
targetPort: 80
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: networking.k8s.io/v1
2+
kind: Ingress
3+
metadata:
4+
name: gatsby-ingress-service
5+
annotations:
6+
nginx.ingress.kubernetes.io/rewrite-target: /$1
7+
spec:
8+
rules:
9+
- host: gatsby.agung96tm.com
10+
http:
11+
paths:
12+
- path: /
13+
pathType: Prefix
14+
backend:
15+
service:
16+
name: gatsby-service
17+
port:
18+
number: 80

0 commit comments

Comments
 (0)