Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx
COPY ./dist /usr/share/nginx/html
11 changes: 11 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
10 changes: 10 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>revision:32</h1>
</body>
</html>
13 changes: 12 additions & 1 deletion ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand All @@ -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
}
}