Skip to content

Instantly share code, notes, and snippets.

@matiasah
Last active May 12, 2021 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matiasah/937ff0634def14308085ce976daedcd9 to your computer and use it in GitHub Desktop.
Save matiasah/937ff0634def14308085ce976daedcd9 to your computer and use it in GitHub Desktop.
Elastic Beanstalk Pipeline (Gitlab Runner)

Environment variables

Environment variable Description
AWS_ACCESS_KEY_ID Access key of the IAM account
AWS_SECRET_ACCESS_KEY Secret key of the IAM account
AWS_REGION Region of the Elastic Beanstalk instance
ELASTIC_BEANSTALK_ENV Name of the elastic beanstalk environment

Pipeline

.gitlab-ci.yml

image: docker:latest

stages:
  - build
  - package
  - deploy

cache:
  key: $CI_COMMIT_REF_SLUG
  paths:
    - .m2/

variables:
  MAVEN_OPTS: -Dmaven.repo.local=${CI_PROJECT_DIR}/.m2

build:
  stage: build
  image: maven:3.6.3-amazoncorretto-11
  script:
    - mvn clean
    - mvn package -Dmaven.test.skip=true
  artifacts:
    paths:
      - .ebextensions
      - target/Backend.jar
    expire_in: 1 day
  cache:
    paths:
      - .m2/

package:
  stage: package
  image: alpine
  script:
    - apk add zip
    - zip -r package.zip .ebextensions
    - zip -j package.zip target/Backend.jar
  artifacts:
    paths:
      - package.zip
    expire_in: 1 day
  dependencies:
    - build

deploy:
  stage: deploy
  image: python:latest
  variables:
    AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
    AWS_REGION: $AWS_REGION
  when: manual
  before_script:
    - pip install awscli
    - pip install awsebcli --upgrade --user
  script:
    - ~/.local/bin/eb use $ELASTIC_BEANSTALK_ENV
    - ~/.local/bin/eb deploy
  dependencies:
    - package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment