Skip to content

Instantly share code, notes, and snippets.

@serhio17
serhio17 / Gitlab_runner_register_access_AWS_ECR.md
Created June 30, 2020 06:56 — forked from piyushsonigra/Gitlab_runner_register_access_AWS_ECR.md
How to configure Gitlab runner to register and access push or pull docker images from AWS ECR private repository

This script can be used as bootstap script to register private Gitlab runner and configure runner to access AWS ECR. You can use Ubuntu 18 LTS AMI and launch AWS EC2 instance to host Gitlab runner.

Attach AWS IAM role to grant EC2 instance to access AWS ECR and push pull docker images. Also awscli aws configure command can be used or export AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variable.

Need to export GITLAB_RUNNER_TOKEN and AWS_REGION as variable to run script successfully.

#!/bin/bash

## AWS docker repository
resource "aws_ecr_repository" "example_app" {
name = "example-app"
}
## example ecs task definition
resource "aws_ecs_task_definition" "example_app" {
family = "example-app"
container_definitions = <<DEFINITION
[