diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ff4a997 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx +COPY ./dist /usr/share/nginx/html diff --git a/Taskfile.yml b/Taskfile.yml index 23751e6..9fd3728 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -8,3 +8,14 @@ tasks: - | aws cloudtrail lookup-events --lookup-attributes AttributeKey=ResourceName,AttributeValue={{.ATTRIBUTES}} --max-items 1 \ | jq -r '.Events[] | .CloudTrailEvent = (.CloudTrailEvent | fromjson ) | select(.EventName == "UpdateService") | {EventTime: .EventTime, EventName: .EventName, Deployments: .CloudTrailEvent.responseElements.service.deployments.[] | {Status: .status, TaskDefinition: .taskDefinition}}' + build_and_push: + desc: "DockerイメージをビルドしてECRにプッシュする" + vars: + PROJECT_NAME: "hamaguchi/nginx" + ECR_REPOSITORY: "533557086642.dkr.ecr.ap-northeast-1.amazonaws.com/{{.PROJECT_NAME}}" + IMAGE_TAG: "latest" + cmds: + - aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin {{.ECR_REPOSITORY}} + - docker build --build-arg project=app --platform linux/amd64 -t {{.PROJECT_NAME}} . + - docker tag {{.PROJECT_NAME}}:latest {{.ECR_REPOSITORY}}:{{.IMAGE_TAG}} + - docker push {{.ECR_REPOSITORY}}:{{.IMAGE_TAG}} diff --git a/dist/index.html b/dist/index.html new file mode 100644 index 0000000..9cc6691 --- /dev/null +++ b/dist/index.html @@ -0,0 +1,10 @@ + + + + + Document + + +

revision:32

+ + diff --git a/ecs.tf b/ecs.tf index 4e90aaf..d349fc8 100644 --- a/ecs.tf +++ b/ecs.tf @@ -30,7 +30,7 @@ resource "aws_ecs_task_definition" "nginx_task" { container_definitions = jsonencode([ { name = "nginx" - image = "public.ecr.aws/nginx/nginx:latest" + image = "${aws_ecr_repository.nginx.repository_url}:latest" portMappings = [ { containerPort = 80 @@ -85,6 +85,9 @@ resource "aws_ecs_service" "nginx_service" { container_name = "nginx" container_port = 80 } + lifecycle { + ignore_changes = [task_definition] + } } resource "aws_cloudwatch_log_group" "nginx_task" { @@ -97,3 +100,11 @@ resource "aws_ecr_pull_through_cache_rule" "ecr_public" { ecr_repository_prefix = "ecr-public" upstream_registry_url = "public.ecr.aws" } + +resource "aws_ecr_repository" "nginx" { + name = "hamaguchi/nginx" + + image_scanning_configuration { + scan_on_push = true + } +}