bookmark_borderUsing Pipelines to Invalidate AWS CloudFront Cache that Pointing to AWS S3 bucket

Steps:

  • Add Repository Variables for Distribution IDs
  • Add Repository Variables for AWS keys as well
  • Add invalidate step in your pipeline
    e.g.
- step:
          name: ">> Invalidate AWS CloudFront (by: Khaled alam)"
          script:
          - pipe: atlassian/aws-cloudfront-invalidate:0.4.1
            variables:
              AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
              AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
              AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
              DISTRIBUTION_ID: $TEST_CLOUDFRONT_DISTRIBUTION_ID
              # PATHS: <string> # Optional
              DEBUG: "true" # Optional

Note: in case you want to invalidate specific files or paths, you should define that in PATHS: <string>

bookmark_borderConfirm AWS Elastic Beanstalk Deployment Progress

Amazon Web Services Elastic Beanstalk

Use case:
You are using Amazon Web Service(AWS) Elastic Beanstalk to handle your deployment process via some git version control pipelines and there is a step that needs to run after your code has been deployed successfully.

There are a lot of solutions that can be used e.g CloudWatch, Lambda Function,.. etc. but I decided to invent my own solution that is easy, interesting and will cost 0$ :))



Idea:
Use a unique value on pipeline level (e.g pipeline build number) and add it to new code before upload it to server then call some endpoint or file to check this value. while this value does not equal out the new unique value in the pipeline then the deployment not finished yet and we should wait!


How to add new value to new code?
– we will create special endpoint or file in our project
– in the pipeline before upload new code to server change value of this file eg. deploy_version.txt or endpoint {api_link}/current_version
e.g: set some variable value with a new unique value. (you can do that using e.g sed Unix-like command)

ex.

we have a static endpoint that returns JSON result with the value of currentVersion variable that placed in e.g `version.js`

const currentVersion='123';

in the pipeline before upload code step:
- sed -i 2"s/currentVersion='123'/currentVersion='$BITBUCKET_BUILD_NUMBER'/g" src/version.js


How to validate deployment progress?

create a bash script that will send curl request to that endpoint to validate if current version from the endpoint(currently deployed code) is equal to new unique pipeline value or not.

how can this bash script look like? email me for more details(khaledalam.net@gmail.com)


bookmark_borderFlutter GitLab CI/CD DevOps

  1. Create .gitlab-ci.yml file in Project root dir
    in the same level of lib folder create file .gitlab-ci.yml
  2. Get a docker:image
    There are some flutter docker images available you can select one or even use your own Docker image

    Flutter docker images examples:
    cirrusci/flutter:stable (github)
    kattwinkel/flutter-android (github)

    Then add it in .gitlab-ci.yml file:
    image: cirrusci/flutter:stable
  3. Define your stages
    Now you need to define stages like that:
    For example:
    stages:
    - test
    - build

    Then start to define tasks that each stage should run:
    For example for stage test:


    test:
    stage: test
    script:
    - flutter packages get
    - flutter packages upgrade
    - flutter test
    interruptible: true

    For example for stage build:


    build:
    stage: build
    script:
    - flutter build apk
    artifacts:
    expire_in: 1 week
    paths:
    - build/app/outputs/apk/release/app-release.apk
    interruptible: true

    Full Example

    .gitlab-ci.yml

    image: cirrusci/flutter:stable

    stages:
    - test
    - build

    test:
    stage: test
    script:
    - flutter packages get
    - flutter packages upgrade
    - flutter test
    interruptible: true

    build:
    stage: build
    script:
    - flutter build apk
    artifacts:
    expire_in: 1 week
    paths:
    - build/app/outputs/apk/release/app-release.apk
    interruptible: true

    You can add more stages like deploy , upgrade , publish etc..