Gitlab CE - deploy to ECS using templates

Hello

I’m trying to use the AWS template to deploy an image to ECS in AWS

According to this, you guys provide a template

When I try to add a template this happens:

the gitlab configuration appears to be invalid?

Do I need to update the templates themselves and place them on my server running gitlab? how can I fix them. I saw they are here: lib/gitlab/ci/templates/AWS · master · GitLab.org / GitLab FOSS · GitLab

Do I need to update them? or how can I debug this issue

  • What version are you on? Are you using self-managed or GitLab.com?
    Yes, I’m using GitLab Community Edition [14.8.2]

Here’s my gitlab-ci.yaml

# --------------------------------------------
# --------------------------------------------
# anchors/fragments used throughout this file

.get_version: &get_version
  - 'export APP_VERSION=$(cat package.json | grep version | head -1 | awk -F: ''{ print $2 }'' | sed ''s/[",]//g'' | tr -d ''[[:space:]]'')'
  - 'echo $APP_VERSION'


.build_docker_image: &build_docker_image
  stage: build
  image: ekino/docker-buildbox:latest-dind-aws
  services:
    - ekino/docker-buildbox:latest-dind-aws
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_HOST: 'tcp://ekino__docker-buildbox:2375'

.pull_node_modules_cache: &pull_node_modules_cache
  cache:
    key: $NODE_MODULE_CACHE_KEY
    policy: pull
    paths:
      - node_modules/

.exclude_short_lived_branches:
  &exclude_short_lived_branches # exclude branches containing a slash (e.g. feature branches) or those starting with a number followed by a dash (i.e. issue branches)
  except:
    - /.+\/.+/
    - /^[0-9]+-.*$/

# --------------------------------------------
# actual fun starts here
# --------------------------------------------
image: node:12.16

variables:
  NODE_MODULE_CACHE_KEY: node_modules_${CI_COMMIT_REF_NAME}
  DOCKER_REPOSITORY_LOCAL: gitlab.okaythis.com:5050/$CI_PROJECT_PATH


include:
  - template: AWS/Deploy-ECS.gitlab-ci.yml


stages:
  - lint
  - test
  - build

run linter:
  stage: lint
  script:
    - yarn install
    - yarn run lint
  cache:
    key: $NODE_MODULE_CACHE_KEY
    policy: pull-push
    paths:
      - node_modules/

unit tests:
  <<: *pull_node_modules_cache
  stage: test
  script:
    - yarn run test
  cache:
    key: $NODE_MODULE_CACHE_KEY
    policy: pull-push
    paths:
      - node_modules/

# dependancy scanning:
#   stage: test
#   script:
#     - yarn global add snyk
#     - snyk auth $SNYK_TOKEN
#     - snyk test --fail-on=upgradable

build app:
  stage: build
  <<: *pull_node_modules_cache
  script:
    - yarn install
    - yarn run build
  artifacts:
    expire_in: 30 minutes
    paths:
      - .next/


build staging docker image:
  <<: *build_docker_image
  only:
    - develop
  script:
    - docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD gitlab.okaythis.com:5050
    - docker pull $DOCKER_REPOSITORY_LOCAL:$APP_VERSION || true
    - docker build --build-arg COMMIT_SHA=$CI_COMMIT_SHORT_SHA --cache-from $DOCKER_REPOSITORY_LOCAL:staging -t app_image .
    - docker tag app_image $DOCKER_REPOSITORY_LOCAL:staging
    - docker push $DOCKER_REPOSITORY_LOCAL:staging

Hi @magg!

It took me a bit to figure this out, you need to apparently define the stages which your include uses. In your case, it looks like this:

stages:
  - lint
  - test
  - build
  - review
  - dast
  - deploy
  - production
  - cleanup

Not claiming it’s the perfect solution (it probably isn’t), but it works for me.

Cheers,

  • Chris