Skip to content

Commit 0b51789

Browse files
committed
📦 feat: Bundler Workflow
1 parent be57601 commit 0b51789

File tree

4 files changed

+260
-283
lines changed

4 files changed

+260
-283
lines changed

‎.github/nginx/default.conf‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
server {
2+
listen 80;
3+
server_name _;
4+
5+
# Enable gzip compression
6+
gzip on;
7+
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
8+
gzip_comp_level 5;
9+
10+
# Set caching headers
11+
location / {
12+
root /usr/share/nginx/html;
13+
index index.html;
14+
try_files $uri $uri/ /index.html;
15+
16+
# Set CORS headers
17+
add_header 'Access-Control-Allow-Origin' '*' always;
18+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
19+
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
20+
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
21+
22+
# Cache settings
23+
expires 1d;
24+
add_header Cache-Control "public, max-age=86400, immutable";
25+
}
26+
27+
# Special handling for worker files
28+
location ~ \.worker\.js$ {
29+
root /usr/share/nginx/html;
30+
31+
add_header 'Access-Control-Allow-Origin' '*' always;
32+
add_header 'Cross-Origin-Embedder-Policy' 'require-corp' always;
33+
add_header 'Cross-Origin-Opener-Policy' 'same-origin' always;
34+
add_header 'Content-Type' 'application/javascript' always;
35+
36+
expires 1d;
37+
add_header Cache-Control "public, max-age=86400, immutable";
38+
}
39+
40+
# Prevent access to .git and other sensitive files
41+
location ~ /\.(?!well-known) {
42+
deny all;
43+
}
44+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
name: Build and Publish Bundler
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
# Allow manual trigger
9+
workflow_dispatch:
10+
# Run monthly to keep the image updated
11+
schedule:
12+
- cron: '0 0 1 * *' # Run on the 1st of every month
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write # Needed for creating releases
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '16'
29+
cache: 'yarn'
30+
31+
- name: Install dependencies
32+
run: yarn install
33+
34+
- name: Build dependencies
35+
run: yarn build:deps
36+
37+
- name: Build Sandpack
38+
run: yarn build:sandpack
39+
40+
# Create a zip archive of the www folder
41+
- name: Create Zip Archive
42+
run: |
43+
cd www
44+
zip -r ../bundler.zip .
45+
cd ..
46+
echo "Created bundler.zip ($(du -h bundler.zip | cut -f1) in size)"
47+
48+
# Upload the zip as an artifact - UPDATED TO V4
49+
- name: Upload Zip Archive
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: bundler-files
53+
path: bundler.zip
54+
retention-days: 90
55+
56+
# Create a release if this is a tag or manually triggered
57+
- name: Create Release
58+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/')
59+
id: create_release
60+
uses: softprops/action-gh-release@v1
61+
with:
62+
files: bundler.zip
63+
name: Bundler Build ${{ github.run_number }}
64+
tag_name: bundler-v${{ github.run_number }}
65+
draft: false
66+
prerelease: false
67+
generate_release_notes: true
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Set up Docker Buildx
72+
uses: docker/setup-buildx-action@v2
73+
74+
- name: Log in to GitHub Container Registry
75+
uses: docker/login-action@v2
76+
with:
77+
registry: ghcr.io
78+
username: ${{ github.actor }}
79+
password: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: Extract metadata
82+
id: meta
83+
uses: docker/metadata-action@v4
84+
with:
85+
images: ghcr.io/${{ github.repository }}/bundler
86+
tags: |
87+
type=raw,value=latest
88+
type=sha,format=short
89+
type=schedule,pattern={{date 'YYYYMMDD'}}
90+
91+
# Create a dedicated directory for Docker build context
92+
- name: Prepare Docker build context
93+
run: |
94+
echo "Preparing Docker build context..."
95+
mkdir -p docker-context
96+
# Check if www directory exists
97+
if [ -d "www" ]; then
98+
echo "Copying www directory to build context"
99+
cp -r www docker-context/
100+
else
101+
echo "ERROR: www directory not found!"
102+
echo "Current directory contents:"
103+
ls -la
104+
exit 1
105+
fi
106+
107+
# Create nginx config directory
108+
mkdir -p docker-context/.github/nginx
109+
110+
# Create a basic nginx config
111+
echo 'server {
112+
listen 80;
113+
server_name _;
114+
115+
# Enable gzip compression
116+
gzip on;
117+
gzip_types text/plain text/css application/javascript application/json;
118+
119+
location / {
120+
root /usr/share/nginx/html;
121+
index index.html;
122+
try_files $uri $uri/ /index.html;
123+
124+
# Set CORS headers
125+
add_header "Access-Control-Allow-Origin" "*" always;
126+
add_header "Cache-Control" "public, max-age=86400, immutable";
127+
}
128+
129+
# Special handling for worker files
130+
location ~ \.worker\.js$ {
131+
root /usr/share/nginx/html;
132+
add_header "Access-Control-Allow-Origin" "*" always;
133+
add_header "Content-Type" "application/javascript" always;
134+
}
135+
}' > docker-context/.github/nginx/default.conf
136+
137+
# Create Dockerfile.bundler in the new context
138+
cat > docker-context/Dockerfile.bundler << 'EOF'
139+
FROM nginx:alpine
140+
COPY www /usr/share/nginx/html
141+
COPY .github/nginx/default.conf /etc/nginx/conf.d/default.conf
142+
EXPOSE 80
143+
HEALTHCHECK --interval=30s --timeout=3s CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
144+
CMD ["nginx", "-g", "daemon off;"]
145+
EOF
146+
147+
echo "Contents of docker-context:"
148+
ls -la docker-context
149+
echo "Contents of docker-context/www (if it exists):"
150+
ls -la docker-context/www || echo "www directory not found in docker-context!"
151+
152+
# Build Docker image with the new context
153+
- name: Build and push Docker image
154+
uses: docker/build-push-action@v4
155+
with:
156+
context: docker-context
157+
file: docker-context/Dockerfile.bundler
158+
push: true
159+
tags: ${{ steps.meta.outputs.tags }}
160+
labels: ${{ steps.meta.outputs.labels }}
161+
cache-from: type=gha
162+
cache-to: type=gha,mode=max
163+
164+
# Add a step to check the directory structure
165+
- name: Check directory structure
166+
run: |
167+
echo "Current directory: $(pwd)"
168+
echo "Contents of current directory:"
169+
ls -la
170+
echo "Contents of www directory (if it exists):"
171+
ls -la www || echo "www directory not found!"
172+
173+
- name: Update deployment status
174+
run: |
175+
echo "Docker image built and pushed: ghcr.io/${{ github.repository }}/bundler:latest"
176+
echo "Image SHA tag: ghcr.io/${{ github.repository }}/bundler:sha-$(git rev-parse --short HEAD)"
177+
echo "Zip archive is available as a build artifact and in the latest release"

‎Dockerfile.bundler‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Nginx image to serve the bundler files
2+
FROM nginx:alpine
3+
4+
# Copy the bundler files (already built by the workflow)
5+
COPY ./www /usr/share/nginx/html
6+
7+
# Copy the custom Nginx configuration
8+
COPY .github/nginx/default.conf /etc/nginx/conf.d/default.conf
9+
10+
# Expose port 80
11+
EXPOSE 80
12+
13+
# Health check
14+
HEALTHCHECK --interval=30s --timeout=3s CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
15+
16+
# Command to run when container starts
17+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)