Optimize CI/CD pipeline for faster deploys
Some checks failed
Deploy / deploy (push) Failing after 1m12s
Some checks failed
Deploy / deploy (push) Failing after 1m12s
- Remove broken npm cache (was timing out ~5min per run) - Replace AWS CLI v2 installer with pip3 install (~50MB less) - Inline AWS credential config instead of separate action - Merge steps to reduce overhead
This commit is contained in:
@@ -46,44 +46,32 @@ jobs:
|
|||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 18
|
||||||
cache: npm
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
if: steps.changes.outputs.frontend == 'true'
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Security check
|
- name: Security check & tests
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
if: steps.changes.outputs.frontend == 'true'
|
||||||
run: npm run security:check
|
run: |
|
||||||
|
npm run security:check
|
||||||
- name: Run tests
|
npm test -- --passWithNoTests
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
|
||||||
run: npm test -- --passWithNoTests
|
|
||||||
|
|
||||||
- name: Build Next.js
|
- name: Build Next.js
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
if: steps.changes.outputs.frontend == 'true'
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
|
||||||
- name: Install AWS CLI
|
- name: Setup AWS
|
||||||
if: steps.changes.outputs.frontend == 'true' || steps.changes.outputs.api == 'true'
|
if: steps.changes.outputs.frontend == 'true' || steps.changes.outputs.api == 'true'
|
||||||
run: |
|
run: |
|
||||||
curl -s "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o /tmp/awscliv2.zip
|
pip3 install -q awscli
|
||||||
unzip -q /tmp/awscliv2.zip -d /tmp
|
aws configure set aws_access_key_id "${{ secrets.AWS_ACCESS_KEY_ID }}"
|
||||||
/tmp/aws/install
|
aws configure set aws_secret_access_key "${{ secrets.AWS_SECRET_ACCESS_KEY }}"
|
||||||
aws --version
|
aws configure set region eu-central-1
|
||||||
|
|
||||||
- name: Configure AWS credentials
|
- name: Deploy to S3 & invalidate CloudFront
|
||||||
if: steps.changes.outputs.frontend == 'true' || steps.changes.outputs.api == 'true'
|
|
||||||
uses: aws-actions/configure-aws-credentials@v4
|
|
||||||
with:
|
|
||||||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
||||||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
||||||
aws-region: eu-central-1
|
|
||||||
|
|
||||||
- name: Deploy to S3
|
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
if: steps.changes.outputs.frontend == 'true'
|
||||||
run: |
|
run: |
|
||||||
# Upload HTML files with no-cache
|
|
||||||
aws s3 sync out/ s3://$S3_BUCKET/ \
|
aws s3 sync out/ s3://$S3_BUCKET/ \
|
||||||
--delete \
|
--delete \
|
||||||
--exclude "*" \
|
--exclude "*" \
|
||||||
@@ -91,19 +79,14 @@ jobs:
|
|||||||
--cache-control "public, max-age=0, must-revalidate" \
|
--cache-control "public, max-age=0, must-revalidate" \
|
||||||
--content-type "text/html"
|
--content-type "text/html"
|
||||||
|
|
||||||
# Upload _next static assets with immutable 1-year cache
|
|
||||||
aws s3 sync out/_next/ s3://$S3_BUCKET/_next/ \
|
aws s3 sync out/_next/ s3://$S3_BUCKET/_next/ \
|
||||||
--cache-control "public, max-age=31536000, immutable"
|
--cache-control "public, max-age=31536000, immutable"
|
||||||
|
|
||||||
# Upload other assets with 1-day cache
|
|
||||||
aws s3 sync out/ s3://$S3_BUCKET/ \
|
aws s3 sync out/ s3://$S3_BUCKET/ \
|
||||||
--exclude "*.html" \
|
--exclude "*.html" \
|
||||||
--exclude "_next/*" \
|
--exclude "_next/*" \
|
||||||
--cache-control "public, max-age=86400"
|
--cache-control "public, max-age=86400"
|
||||||
|
|
||||||
- name: Invalidate CloudFront
|
|
||||||
if: steps.changes.outputs.frontend == 'true'
|
|
||||||
run: |
|
|
||||||
aws cloudfront create-invalidation \
|
aws cloudfront create-invalidation \
|
||||||
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
|
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
|
||||||
--paths "/*"
|
--paths "/*"
|
||||||
|
|||||||
Reference in New Issue
Block a user