MathieuLoutre / grunt-aws-s3

Grunt plugin to interact with AWS S3 using the AWS SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gzip'd files always get uploaded

ianpogi5 opened this issue · comments

I gzip all my files before uploading to s3. For some reason, everything gets always upload even if there was only 1 file changed.

If I don't gzip them, everything works correctly.

Hi there! Can you share your config? I think it might have been a bug in 0.14.0 which I've just fixed in 0.14.1. Can you try the latest version and let me know here?

Hi Matieu,

Still doesn't work.

Here's my config:

aws_s3: {
            options: {
                accessKeyId: 'xxx',
                secretAccessKey: 'xxx', // You can also use env variables
                region: 'ap-southeast-1',
                uploadConcurrency: 8
            },
            production: {
                options: {
                    bucket: 'mybucket',
                    differential: true,
                    displayChangesOnly: true,
                    params: {
                        ContentEncoding: 'gzip' // applies to all the files!
                    }
                },
                files: [
                    {expand: true, cwd: 'public', src: [
                        '**/*.html',
                        '**/*.css',
                        '**/*.js',
                        '**/*.xml'
                    ], dest: '/', action: 'upload', params: {CacheControl: 'max-age=86400, public'}}, // 24 hrs

                    // images
                    {expand: true, cwd: 'public', src: [
                        '**/*.gif',
                        '**/*.ico',
                        '**/*.jpeg',
                        '**/*.jpg',
                        '**/*.otf',
                        '**/*.png',
                        '**/*.svg',
                        '**/*.ttf',
                        '**/*.woff',
                        '**/*.eot'
                    ], dest: '/', action: 'upload', params: {CacheControl: 'max-age=31536000, public'}}, // 1 yr
                ]
            }
        },

Here's my task:

// Production tasks
    grunt.registerTask('production', [
        'shell:hexo_clean',
        'shell:hexo_production',
        'replace:production',
        'htmlmin:minify',
        'uglify:minify',
        'cssmin:minify',
        'shell:gzip',
        'aws_s3:production',
        'cloudfront:production'
    ]);

If I remove 'shell:gzip', it will upload only the changed files.

Here's my gzip script:

#!/bin/bash

find public -type f  | while read file; do
    echo "compressing $file"
    gzip -9 $file
    mv -f "$file.gz" $file
done

Here's a configuration that works for me:

        aws_s3:
            options:
                accessKeyId: "<%= config.s3.key %>"
                secretAccessKey: "<%= config.s3.secret %>"
                region: "<%= config.s3.region %>"
                uploadConcurrency: 5
                stream: true
                params:
                    CacheControl: 'max-age=31536000'
            deploy:
                options:
                    bucket: "<%= config.s3.bucket %>"
                files: [
                    expand: true
                    cwd: 'dist/app'
                    src: [
                        'fonts/**'
                        'images/**'
                        'sounds/**'
                        'scripts/build.js'
                        'styles/build.css'
                        'scripts/build.js.gz'
                        'styles/build.css.gz'
                    ]
                    dest: '<%= config.s3.path %>'
                ]

I think you may have a problem with the naming of your files. For instance I don't see any .gz extensions in your file list. If you're swapping the extensions, have a look at the gzip convention (https://github.com/MathieuLoutre/grunt-aws-s3#gzip) and the gzipRename option (https://github.com/MathieuLoutre/grunt-aws-s3#optionsgziprename)

I don't need to swap extensions because it's done in my gzip script.

I've fixed my issue by adding "-n" in my gzip command so that it forget's the timestamp.

Here's my new gzip script:

#!/bin/bash

find public -type f  | while read file; do
    echo "compressing $file"
    gzip -9 -n $file
    mv -f "$file.gz" $file
done

Thanks for your great work!