Introduction to Quarkus With Gitlab and Amazon Ecs
1. Introduction In this article, I will share the GitLab configuration on how we can build a Quarkus project in GitLab and deploy it on Ama...
https://www.czetsuyatech.com/2021/07/javaee-quarkus-with-gitlab-and-aws-ecs.html
1. Introduction
In this article, I will share the GitLab configuration on how we can build a Quarkus project in GitLab and deploy it on Amazon ECS.
2. Prerequisites
2.1 Amazon
For this section, the links are provided below.
- Create a container repository. Copy the container link as we will use it when we create the ECS cluster.
- Create an ECS cluster. Take note of the cluster and service name, we will need it in the GitLab configuration.
2.2 GitLab
The following CI/CD variables must be set:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_DEFAULT_REGION
In GitLab, click Settings / CI/CD / Variables.
3. GitLab Configuration
Here is the actual GitLab's configuration.
image: maven:3.6.3-openjdk-11 variables: MAVEN_OPTS: >- -Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true MAVEN_CLI_OPTS: >- --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true CI_AWS_ECS_CLUSTER: quarkus-cognito CI_AWS_ECS_SERVICE: quarkus-cognito CI_AWS_REGISTRY_IMG: xxx.dkr.ecr.us-east-2.amazonaws.com/quarkus-cognito cache: paths: - .m2/repository - target before_script: - >- echo " ------------------------------- Global > Before Script ------------------------- ------" - echo $CI_COMMIT_BRANCH stages: - compile - build - deploy compile-project: stage: compile before_script: - apt-get update -qq - apt-get install -y -qq build-essential libz-dev zlib1g-dev - ls -la - chmod +x ./mvnw script: - echo "Building native app." - ./mvnw package kaniko-build-docker: image: name: gcr.io/kaniko-project/executor:debug entrypoint: [""] stage: build variables: REGISTRY: $CI_AWS_REGISTRY_IMG before_script: - ls -la only: - master script: # see https://github.com/GoogleContainerTools/kaniko/issues/1227 - mkdir -p /kaniko/.docker - echo "{\"credsStore\":\"ecr-login\"}" > /kaniko/.docker/config.json - /kaniko/executor --cache=true --context $CI_PROJECT_DIR --dockerfile ${CI_PROJECT_DIR}/src/main/docker/Dockerfile.jvm --destination $REGISTRY:$CI_COMMIT_SHORT_SHA --destination $REGISTRY:latest
deploy: image: python:3.8 stage: deploy only: - master before_script: - pip install ecs-deploy needs: - kaniko-build-docker script: - ecs deploy $CI_AWS_ECS_CLUSTER $CI_AWS_ECS_SERVICE -t $CI_COMMIT_SHORT_SHA --timeout 600
4. References
- https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html
- https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html
- https://docs.amazonaws.cn/en_us/AmazonECS/latest/userguide/create_cluster.html
- https://forum.gitlab.com/t/docker-deployment-to-either-amazon-ecs-or-ecr/41241
Post a Comment