Skip to content

Commit 320d29d

Browse files
committed
fix: s3cmd for content type settings for s3 upload
1 parent 243eea8 commit 320d29d

File tree

1 file changed

+26
-96
lines changed

1 file changed

+26
-96
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -85,111 +85,41 @@ jobs:
8585
echo "Clearing existing files from bucket..."
8686
s3cmd del --recursive --force s3://${{ secrets.S3_BUCKET_NAME }}/
8787
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-
105-
# Upload all files with progress display
88+
# Upload all files first - this will use auto mime-type detection
10689
echo "Uploading files to S3-compatible storage..."
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
17390
s3cmd sync --verbose --progress \
17491
--exclude=".git/*" \
175-
--exclude=".meta/*" \
176-
--exclude="upload.sh" \
17792
--no-check-md5 \
17893
--delete-removed \
179-
--skip-existing \
18094
--guess-mime-type \
181-
--no-preserve \
182-
--meta-dir=.meta \
18395
--add-header="Content-Disposition: inline" \
184-
./ s3://$1/
185-
186-
EOL
96+
./ s3://${{ secrets.S3_BUCKET_NAME }}/
97+
98+
# Set content types for specific file types to ensure proper handling
99+
echo "Setting content types for HTML files..."
100+
find . -name "*.html" | while read file; do
101+
rel_path=${file#./}
102+
echo "Setting content-type for: $rel_path"
103+
s3cmd modify --mime-type="text/html" \
104+
--add-header="Content-Disposition: inline" \
105+
s3://${{ secrets.S3_BUCKET_NAME }}/$rel_path
106+
done
187107
188-
# Make script executable
189-
chmod +x upload.sh
108+
echo "Setting content types for CSS files..."
109+
find . -name "*.css" | while read file; do
110+
rel_path=${file#./}
111+
s3cmd modify --mime-type="text/css" \
112+
--add-header="Content-Disposition: inline" \
113+
s3://${{ secrets.S3_BUCKET_NAME }}/$rel_path
114+
done
190115
191-
# Run upload script
192-
./upload.sh ${{ secrets.S3_BUCKET_NAME }}
116+
echo "Setting content types for JavaScript files..."
117+
find . -name "*.js" | while read file; do
118+
rel_path=${file#./}
119+
s3cmd modify --mime-type="application/javascript" \
120+
--add-header="Content-Disposition: inline" \
121+
s3://${{ secrets.S3_BUCKET_NAME }}/$rel_path
122+
done
193123
194124
echo "Successfully deployed to S3-compatible storage"
195125
env:

0 commit comments

Comments
 (0)