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