4646 # Extract domain from endpoint URL (remove https:// if present)
4747 ENDPOINT=$(echo "${{ secrets.S3_ENDPOINT_URL }}" | sed 's/https:\/\///')
4848
49- # Create s3cmd config file
49+ # Create s3cmd config file with MIME type settings
5050 cat > ~/.s3cfg << EOF
5151 [default]
5252 access_key = ${{ secrets.S3_ACCESS_KEY }}
5959 # Enable verbose output and progress meter
6060 verbose = True
6161 progress_meter = True
62+ # Enable proper MIME types detection
63+ guess_mime_type = True
6264 EOF
6365
6466 - name : Deploy to S3-compatible storage with s3cmd
@@ -83,10 +85,111 @@ jobs:
8385 echo "Clearing existing files from bucket..."
8486 s3cmd del --recursive --force s3://${{ secrets.S3_BUCKET_NAME }}/
8587
88+ # Create a mime type mapping file
89+ echo "Setting up MIME type mappings..."
90+ cat > /tmp/mime.types << EOL
91+ text/html: html htm
92+ text/css: css
93+ application/javascript: js
94+ application/json: json
95+ image/svg+xml: svg
96+ image/png: png
97+ image/jpeg: jpg jpeg
98+ image/gif: gif
99+ application/pdf: pdf
100+ text/plain: txt md
101+ application/font-woff: woff
102+ application/font-woff2: woff2
103+ EOL
104+
86105 # Upload all files with progress display
87106 echo "Uploading files to S3-compatible storage..."
88- s3cmd sync --verbose --progress --exclude=".git/*" \
89- --no-check-md5 ./ s3://${{ secrets.S3_BUCKET_NAME }}/
107+
108+ # Create a script to upload files with proper content types
109+ cat > upload.sh << 'EOL'
110+ #!/bin/bash
111+
112+ # Set up empty meta files directory
113+ mkdir -p .meta
114+
115+ # Process each file type and create meta files
116+ find . -type f -not -path "./.git/*" -not -path "./.meta/*" -not -name "upload.sh" | while read file; do
117+ # Skip directories
118+ if [ -d "$file" ]; then continue; fi
119+
120+ # Get file extension
121+ ext="${file##*.}"
122+ content_type=""
123+
124+ # Set content type based on extension
125+ case "$ext" in
126+ html|htm)
127+ content_type="text/html"
128+ ;;
129+ css)
130+ content_type="text/css"
131+ ;;
132+ js)
133+ content_type="application/javascript"
134+ ;;
135+ json)
136+ content_type="application/json"
137+ ;;
138+ svg)
139+ content_type="image/svg+xml"
140+ ;;
141+ png)
142+ content_type="image/png"
143+ ;;
144+ jpg|jpeg)
145+ content_type="image/jpeg"
146+ ;;
147+ gif)
148+ content_type="image/gif"
149+ ;;
150+ pdf)
151+ content_type="application/pdf"
152+ ;;
153+ woff)
154+ content_type="application/font-woff"
155+ ;;
156+ woff2)
157+ content_type="application/font-woff2"
158+ ;;
159+ *)
160+ content_type="binary/octet-stream"
161+ ;;
162+ esac
163+
164+ # Create meta file if content type was determined
165+ if [ ! -z "$content_type" ]; then
166+ meta_file=".meta/${file}"
167+ mkdir -p "$(dirname "$meta_file")"
168+ echo "Content-Type: $content_type" > "$meta_file"
169+ fi
170+ done
171+
172+ # Upload with s3cmd using meta files for content types
173+ s3cmd sync --verbose --progress \
174+ --exclude=".git/*" \
175+ --exclude=".meta/*" \
176+ --exclude="upload.sh" \
177+ --no-check-md5 \
178+ --delete-removed \
179+ --skip-existing \
180+ --guess-mime-type \
181+ --no-preserve \
182+ --meta-dir=.meta \
183+ --add-header="Content-Disposition: inline" \
184+ ./ s3://$1/
185+
186+ EOL
187+
188+ # Make script executable
189+ chmod +x upload.sh
190+
191+ # Run upload script
192+ ./upload.sh ${{ secrets.S3_BUCKET_NAME }}
90193
91194 echo "Successfully deployed to S3-compatible storage"
92195 env :
0 commit comments