From 1d18752bf55a78026bf3143003c4216c269facc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChathumiii=E2=80=9D?= <“chathumirambukwella@gmail.com”> Date: Thu, 9 Mar 2023 01:08:38 +0000 Subject: [PATCH 01/16] Added Terraform Code --- terraform/config.tf | 4 + terraform/docker | 27 ++ terraform/docker.pub | 1 + terraform/main.tf | 26 ++ terraform/network.tf | 13 + terraform/securitygroup.tf | 31 ++ terraform/terraform.tfstate | 445 +++++++++++++++++++++++++++++ terraform/terraform.tfstate.backup | 323 +++++++++++++++++++++ 8 files changed, 870 insertions(+) create mode 100644 terraform/config.tf create mode 100644 terraform/docker create mode 100644 terraform/docker.pub create mode 100644 terraform/main.tf create mode 100644 terraform/network.tf create mode 100644 terraform/securitygroup.tf create mode 100644 terraform/terraform.tfstate create mode 100644 terraform/terraform.tfstate.backup diff --git a/terraform/config.tf b/terraform/config.tf new file mode 100644 index 0000000..175c488 --- /dev/null +++ b/terraform/config.tf @@ -0,0 +1,4 @@ +//Terraform deployment codes +provider "aws" { + region = "us-east-1" +} diff --git a/terraform/docker b/terraform/docker new file mode 100644 index 0000000..1d71f51 --- /dev/null +++ b/terraform/docker @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAo/RNx83nVpV4o+EF2ESg5MGE/40PUyKg7Z045CZOn3+kXfYO +XhPiLtWZImz9SuioJIdqOBK6XGFd06tgw/BMGItPQYjuvJVoHJS4XwTHClMc2ljX +PJUi2dHrb7LY5KzkXj6/fg9CHCxfWEM+ipyTo4QisrcS3pB2MgdnpMzS1m1rMoeH +Ei+QuNYbyH/mMxMpNHsnS8Pq0W59r3W9U4Lt5NLoEsN9GpZ8sF54hsqZN/4OTdC2 +U0CAmsbmvVjYNufSOM+Z8Q2oQvtEblSEcGgqEF/nh5jA+qydNcqPR+aaLx9arQfN +MP9gTobtMophbQA3ZmSYjjVLmfejHAhrIG5zzwIDAQABAoIBABbF5VPebsahBlvE +8rnidnKvyphwcHN8uNuoXfGavIr9AMioV8CLhHw64QVeHCSeglRolsFpIIeaYpz3 +Df7JTtiN6RlSOs7o9cgahC12jWsKtlRByMu6b1fQB6LBNc01kpbgolqRJf6hzzCE +TpiUPRGWVfd65F0TtccnLic+5/4uhaLSOfecS1jGxbFVGQ0eziXiOYqZz69YsnWd +cCSu4M0Vgivfn9WH1PS4XAqcCWO2htU2K05e5DBhBu+0oC+ErXESg7X1U5PjwVrW +zqGXhkNlJTMihM+7WRqey/9urvLzJCYfQRwezNpcLnPh5REemD1WiYlt3be5e1NA +beOZUkkCgYEA1TLNJeKIrg0Eghcx/bls0AULD6qNZ02kq7c6BiOTBau7NRWmbwPO +1YHwRqr1rEA4xYtP41PuQeIhGL5DwOFh4yKqyp01pFku3+PktlQezCl8Hvsa7hUs +y36Swy4+Eg9rZA0111Ktp7wJLm4XmgLZTPVPAM4hRAh2V76zqL63I+sCgYEAxN6h +saZEAfEGbfWB7JMwbDupJB7+0qzrxQZE8lNe+k6RzOD/JAxiSRiDmk6R2nEtob89 +rlai6bopBA45g1IfyzWHo4b/bZeHy3sa+WFEVkE8dyBBawEq3Y5jARrZM4NlIgnG +VtpM20VgyL/FLfo0mfTt6lG2vibbyqB3dWjMCq0CgYEAlO4g+ucNnbBARvQXGuvu +BD6RpIb6soA9mSqsoN829A4r/4A5PHHHicR0aZlBduuB/RU9YEsgM+vYPOWkhNes +vrNX5aP+delK4mHbQjbvMKWGLEozXL90BE9ODISAHbOhzEmiI+GAp5ymOUX0vMRi +seznHGPiPxk+OjtgW2+mlbMCgYAVp8uvh/OJJyMm60+cX2B/N1zWrVYohH720Ea7 +RTJ4ZDYjjEhkhbw2AC1RxvzCQ5raZPf6+mq3PRQP7ySibmEy8DN4aHwmaPm2B1ej +QPDMcCafj/vCMoGtl2EKmRJ1WSnBwcOAgEjeAdawnm+pLBGnMcsN8Gkip5Gby2T4 +lEuFjQKBgErZuKLPq0zCkUNKgVpDVWlYMpz+BlKUDtfrVG8NM3Aca/cSrdi2Emxw +bjsf9NbhLlHAiqbwtPSJIuiKCmzF7WRU97mwM+om8CyLN6oHsVoXp/Ap06mWIooi +tiEf0u4LKF2KQGsgZ2C7JynVAkGSzLUWvsqAeqMeQqAj1pQKs4Y5 +-----END RSA PRIVATE KEY----- diff --git a/terraform/docker.pub b/terraform/docker.pub new file mode 100644 index 0000000..c567805 --- /dev/null +++ b/terraform/docker.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCj9E3HzedWlXij4QXYRKDkwYT/jQ9TIqDtnTjkJk6ff6Rd9g5eE+Iu1ZkibP1K6Kgkh2o4ErpcYV3Tq2DD8EwYi09BiO68lWgclLhfBMcKUxzaWNc8lSLZ0etvstjkrORePr9+D0IcLF9YQz6KnJOjhCKytxLekHYyB2ekzNLWbWsyh4cSL5C41hvIf+YzEyk0eydLw+rRbn2vdb1Tgu3k0ugSw30alnywXniGypk3/g5N0LZTQICaxua9WNg259I4z5nxDahC+0RuVIRwaCoQX+eHmMD6rJ01yo9H5povH1qtB80w/2BOhu0yimFtADdmZJiONUuZ96McCGsgbnPP ec2-user@ip-172-31-70-78.ec2.internal diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..9738c10 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,26 @@ +data "aws_ami" "latestLinuxAMI" { + owners = ["amazon"] + most_recent = true + filter { + name = "name" + values = ["amzn2-ami-hvm-*-x86_64-gp2"] + } +} + +resource "aws_instance" "ec2" { + ami = data.aws_ami.latestLinuxAMI.id + instance_type = "t2.micro" + subnet_id = aws_subnet.this.id + iam_instance_profile = "LabInstanceProfile" + security_groups = [aws_security_group.docker_sg.id] + key_name = "docker" +} + + +resource "aws_ecr_repository" "database" { + name = "database" +} + +resource "aws_ecr_repository" "application" { + name = "application" +} \ No newline at end of file diff --git a/terraform/network.tf b/terraform/network.tf new file mode 100644 index 0000000..b4fd2a4 --- /dev/null +++ b/terraform/network.tf @@ -0,0 +1,13 @@ +data "aws_vpc" "default" { + default = true +} + +resource "aws_subnet" "this" { + vpc_id = data.aws_vpc.default.id + cidr_block = "172.31.128.0/20" + map_public_ip_on_launch = true + + tags = { + Name = "Public Subnet" + } +} \ No newline at end of file diff --git a/terraform/securitygroup.tf b/terraform/securitygroup.tf new file mode 100644 index 0000000..fa008b3 --- /dev/null +++ b/terraform/securitygroup.tf @@ -0,0 +1,31 @@ +resource "aws_security_group" "docker_sg" { + name = "docker_security_group" + description = "Security group for Docker Compose app" + vpc_id = data.aws_vpc.default.id + + ingress { + from_port = 5000 + to_port = 5000 + protocol = "tcp" + cidr_blocks = ["10.0.0.0/16"] + } + + ingress { + from_port = 3306 + to_port = 3306 + protocol = "tcp" + cidr_blocks = ["10.0.0.0/16"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Terraform = "true" + Environment = "dev" + } +} \ No newline at end of file diff --git a/terraform/terraform.tfstate b/terraform/terraform.tfstate new file mode 100644 index 0000000..ae3f065 --- /dev/null +++ b/terraform/terraform.tfstate @@ -0,0 +1,445 @@ +{ + "version": 4, + "terraform_version": "1.3.9", + "serial": 8, + "lineage": "73106bf0-260e-c6c8-57fd-9c554c6ab538", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "aws_ami", + "name": "latestLinuxAMI", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "architecture": "x86_64", + "arn": "arn:aws:ec2:us-east-1::image/ami-05b5badc2f7ddd88d", + "block_device_mappings": [ + { + "device_name": "/dev/xvda", + "ebs": { + "delete_on_termination": "true", + "encrypted": "false", + "iops": "0", + "snapshot_id": "snap-07d0aaf53127ea133", + "throughput": "0", + "volume_size": "8", + "volume_type": "gp2" + }, + "no_device": "", + "virtual_name": "" + } + ], + "boot_mode": "", + "creation_date": "2023-02-24T09:54:00.000Z", + "deprecation_time": "2025-02-24T09:54:00.000Z", + "description": "Amazon Linux 2 AMI 2.0.20230221.0 x86_64 HVM gp2", + "ena_support": true, + "executable_users": null, + "filter": [ + { + "name": "name", + "values": [ + "amzn2-ami-hvm-*-x86_64-gp2" + ] + } + ], + "hypervisor": "xen", + "id": "ami-05b5badc2f7ddd88d", + "image_id": "ami-05b5badc2f7ddd88d", + "image_location": "amazon/amzn2-ami-hvm-2.0.20230221.0-x86_64-gp2", + "image_owner_alias": "amazon", + "image_type": "machine", + "imds_support": "", + "include_deprecated": false, + "kernel_id": "", + "most_recent": true, + "name": "amzn2-ami-hvm-2.0.20230221.0-x86_64-gp2", + "name_regex": null, + "owner_id": "137112412989", + "owners": [ + "amazon" + ], + "platform": "", + "platform_details": "Linux/UNIX", + "product_codes": [], + "public": true, + "ramdisk_id": "", + "root_device_name": "/dev/xvda", + "root_device_type": "ebs", + "root_snapshot_id": "snap-07d0aaf53127ea133", + "sriov_net_support": "simple", + "state": "available", + "state_reason": { + "code": "UNSET", + "message": "UNSET" + }, + "tags": {}, + "timeouts": null, + "tpm_support": "", + "usage_operation": "RunInstances", + "virtualization_type": "hvm" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "aws_vpc", + "name": "default", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:vpc/vpc-0c375df36a4e25b86", + "cidr_block": "172.31.0.0/16", + "cidr_block_associations": [ + { + "association_id": "vpc-cidr-assoc-0e99fad12f87beb2f", + "cidr_block": "172.31.0.0/16", + "state": "associated" + } + ], + "default": true, + "dhcp_options_id": "dopt-03a42c3fb651c17ce", + "enable_dns_hostnames": true, + "enable_dns_support": true, + "enable_network_address_usage_metrics": false, + "filter": null, + "id": "vpc-0c375df36a4e25b86", + "instance_tenancy": "default", + "ipv6_association_id": "", + "ipv6_cidr_block": "", + "main_route_table_id": "rtb-021a57da877c4ff63", + "owner_id": "244069240907", + "state": null, + "tags": {}, + "timeouts": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "aws_ecr_repository", + "name": "application", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ecr:us-east-1:244069240907:repository/application", + "encryption_configuration": [ + { + "encryption_type": "AES256", + "kms_key": "" + } + ], + "force_delete": null, + "id": "application", + "image_scanning_configuration": [ + { + "scan_on_push": false + } + ], + "image_tag_mutability": "MUTABLE", + "name": "application", + "registry_id": "244069240907", + "repository_url": "244069240907.dkr.ecr.us-east-1.amazonaws.com/application", + "tags": {}, + "tags_all": {}, + "timeouts": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxMjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "aws_ecr_repository", + "name": "database", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ecr:us-east-1:244069240907:repository/database", + "encryption_configuration": [ + { + "encryption_type": "AES256", + "kms_key": "" + } + ], + "force_delete": null, + "id": "database", + "image_scanning_configuration": [ + { + "scan_on_push": false + } + ], + "image_tag_mutability": "MUTABLE", + "name": "database", + "registry_id": "244069240907", + "repository_url": "244069240907.dkr.ecr.us-east-1.amazonaws.com/database", + "tags": {}, + "tags_all": {}, + "timeouts": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxMjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "aws_instance", + "name": "ec2", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "ami": "ami-05b5badc2f7ddd88d", + "arn": "arn:aws:ec2:us-east-1:244069240907:instance/i-0b1e9233088e80cfa", + "associate_public_ip_address": true, + "availability_zone": "us-east-1f", + "capacity_reservation_specification": [ + { + "capacity_reservation_preference": "open", + "capacity_reservation_target": [] + } + ], + "cpu_core_count": 1, + "cpu_threads_per_core": 1, + "credit_specification": [ + { + "cpu_credits": "standard" + } + ], + "disable_api_stop": false, + "disable_api_termination": false, + "ebs_block_device": [], + "ebs_optimized": false, + "enclave_options": [ + { + "enabled": false + } + ], + "ephemeral_block_device": [], + "get_password_data": false, + "hibernation": false, + "host_id": "", + "host_resource_group_arn": null, + "iam_instance_profile": "LabInstanceProfile", + "id": "i-0b1e9233088e80cfa", + "instance_initiated_shutdown_behavior": "stop", + "instance_state": "running", + "instance_type": "t2.micro", + "ipv6_address_count": 0, + "ipv6_addresses": [], + "key_name": "docker", + "launch_template": [], + "maintenance_options": [ + { + "auto_recovery": "default" + } + ], + "metadata_options": [ + { + "http_endpoint": "enabled", + "http_put_response_hop_limit": 1, + "http_tokens": "optional", + "instance_metadata_tags": "disabled" + } + ], + "monitoring": false, + "network_interface": [], + "outpost_arn": "", + "password_data": "", + "placement_group": "", + "placement_partition_number": 0, + "primary_network_interface_id": "eni-09f14146e9b4e8220", + "private_dns": "ip-172-31-137-200.ec2.internal", + "private_dns_name_options": [ + { + "enable_resource_name_dns_a_record": false, + "enable_resource_name_dns_aaaa_record": false, + "hostname_type": "ip-name" + } + ], + "private_ip": "172.31.137.200", + "public_dns": "ec2-3-235-77-26.compute-1.amazonaws.com", + "public_ip": "3.235.77.26", + "root_block_device": [ + { + "delete_on_termination": true, + "device_name": "/dev/xvda", + "encrypted": false, + "iops": 100, + "kms_key_id": "", + "tags": {}, + "throughput": 0, + "volume_id": "vol-0174584b6ab465186", + "volume_size": 8, + "volume_type": "gp2" + } + ], + "secondary_private_ips": [], + "security_groups": [ + "sg-07ccce6631c3ec977" + ], + "source_dest_check": true, + "subnet_id": "subnet-09d1b4944d86dfd07", + "tags": null, + "tags_all": {}, + "tenancy": "default", + "timeouts": null, + "user_data": null, + "user_data_base64": null, + "user_data_replace_on_change": false, + "volume_tags": null, + "vpc_security_group_ids": [ + "sg-07ccce6631c3ec977" + ] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwidXBkYXRlIjo2MDAwMDAwMDAwMDB9LCJzY2hlbWFfdmVyc2lvbiI6IjEifQ==", + "dependencies": [ + "aws_security_group.docker_sg", + "aws_subnet.this", + "data.aws_ami.latestLinuxAMI" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_security_group", + "name": "docker_sg", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:security-group/sg-07ccce6631c3ec977", + "description": "Security group for Docker Compose app", + "egress": [ + { + "cidr_blocks": [ + "0.0.0.0/0" + ], + "description": "", + "from_port": 0, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "-1", + "security_groups": [], + "self": false, + "to_port": 0 + } + ], + "id": "sg-07ccce6631c3ec977", + "ingress": [ + { + "cidr_blocks": [ + "10.0.0.0/16" + ], + "description": "", + "from_port": 3306, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 3306 + }, + { + "cidr_blocks": [ + "10.0.0.0/16" + ], + "description": "", + "from_port": 5000, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 5000 + } + ], + "name": "docker_security_group", + "name_prefix": "", + "owner_id": "244069240907", + "revoke_rules_on_delete": false, + "tags": { + "Environment": "dev", + "Terraform": "true" + }, + "tags_all": { + "Environment": "dev", + "Terraform": "true" + }, + "timeouts": null, + "vpc_id": "vpc-0c375df36a4e25b86" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6OTAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0=", + "dependencies": [ + "data.aws_vpc.default" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_subnet", + "name": "this", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:subnet/subnet-09d1b4944d86dfd07", + "assign_ipv6_address_on_creation": false, + "availability_zone": "us-east-1f", + "availability_zone_id": "use1-az5", + "cidr_block": "172.31.128.0/20", + "customer_owned_ipv4_pool": "", + "enable_dns64": false, + "enable_resource_name_dns_a_record_on_launch": false, + "enable_resource_name_dns_aaaa_record_on_launch": false, + "id": "subnet-09d1b4944d86dfd07", + "ipv6_cidr_block": "", + "ipv6_cidr_block_association_id": "", + "ipv6_native": false, + "map_customer_owned_ip_on_launch": false, + "map_public_ip_on_launch": true, + "outpost_arn": "", + "owner_id": "244069240907", + "private_dns_hostname_type_on_launch": "ip-name", + "tags": { + "Name": "Public Subnet" + }, + "tags_all": { + "Name": "Public Subnet" + }, + "timeouts": null, + "vpc_id": "vpc-0c375df36a4e25b86" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMSJ9", + "dependencies": [ + "data.aws_vpc.default" + ] + } + ] + } + ], + "check_results": null +} diff --git a/terraform/terraform.tfstate.backup b/terraform/terraform.tfstate.backup new file mode 100644 index 0000000..ba7fd86 --- /dev/null +++ b/terraform/terraform.tfstate.backup @@ -0,0 +1,323 @@ +{ + "version": 4, + "terraform_version": "1.3.9", + "serial": 6, + "lineage": "73106bf0-260e-c6c8-57fd-9c554c6ab538", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "aws_ami", + "name": "latestLinuxAMI", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "architecture": "x86_64", + "arn": "arn:aws:ec2:us-east-1::image/ami-05b5badc2f7ddd88d", + "block_device_mappings": [ + { + "device_name": "/dev/xvda", + "ebs": { + "delete_on_termination": "true", + "encrypted": "false", + "iops": "0", + "snapshot_id": "snap-07d0aaf53127ea133", + "throughput": "0", + "volume_size": "8", + "volume_type": "gp2" + }, + "no_device": "", + "virtual_name": "" + } + ], + "boot_mode": "", + "creation_date": "2023-02-24T09:54:00.000Z", + "deprecation_time": "2025-02-24T09:54:00.000Z", + "description": "Amazon Linux 2 AMI 2.0.20230221.0 x86_64 HVM gp2", + "ena_support": true, + "executable_users": null, + "filter": [ + { + "name": "name", + "values": [ + "amzn2-ami-hvm-*-x86_64-gp2" + ] + } + ], + "hypervisor": "xen", + "id": "ami-05b5badc2f7ddd88d", + "image_id": "ami-05b5badc2f7ddd88d", + "image_location": "amazon/amzn2-ami-hvm-2.0.20230221.0-x86_64-gp2", + "image_owner_alias": "amazon", + "image_type": "machine", + "imds_support": "", + "include_deprecated": false, + "kernel_id": "", + "most_recent": true, + "name": "amzn2-ami-hvm-2.0.20230221.0-x86_64-gp2", + "name_regex": null, + "owner_id": "137112412989", + "owners": [ + "amazon" + ], + "platform": "", + "platform_details": "Linux/UNIX", + "product_codes": [], + "public": true, + "ramdisk_id": "", + "root_device_name": "/dev/xvda", + "root_device_type": "ebs", + "root_snapshot_id": "snap-07d0aaf53127ea133", + "sriov_net_support": "simple", + "state": "available", + "state_reason": { + "code": "UNSET", + "message": "UNSET" + }, + "tags": {}, + "timeouts": null, + "tpm_support": "", + "usage_operation": "RunInstances", + "virtualization_type": "hvm" + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "aws_vpc", + "name": "default", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:vpc/vpc-0c375df36a4e25b86", + "cidr_block": "172.31.0.0/16", + "cidr_block_associations": [ + { + "association_id": "vpc-cidr-assoc-0e99fad12f87beb2f", + "cidr_block": "172.31.0.0/16", + "state": "associated" + } + ], + "default": true, + "dhcp_options_id": "dopt-03a42c3fb651c17ce", + "enable_dns_hostnames": true, + "enable_dns_support": true, + "enable_network_address_usage_metrics": false, + "filter": null, + "id": "vpc-0c375df36a4e25b86", + "instance_tenancy": "default", + "ipv6_association_id": "", + "ipv6_cidr_block": "", + "main_route_table_id": "rtb-021a57da877c4ff63", + "owner_id": "244069240907", + "state": null, + "tags": {}, + "timeouts": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "aws_ecr_repository", + "name": "application", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ecr:us-east-1:244069240907:repository/application", + "encryption_configuration": [ + { + "encryption_type": "AES256", + "kms_key": "" + } + ], + "force_delete": null, + "id": "application", + "image_scanning_configuration": [ + { + "scan_on_push": false + } + ], + "image_tag_mutability": "MUTABLE", + "name": "application", + "registry_id": "244069240907", + "repository_url": "244069240907.dkr.ecr.us-east-1.amazonaws.com/application", + "tags": null, + "tags_all": {}, + "timeouts": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxMjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "aws_ecr_repository", + "name": "database", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "arn": "arn:aws:ecr:us-east-1:244069240907:repository/database", + "encryption_configuration": [ + { + "encryption_type": "AES256", + "kms_key": "" + } + ], + "force_delete": null, + "id": "database", + "image_scanning_configuration": [ + { + "scan_on_push": false + } + ], + "image_tag_mutability": "MUTABLE", + "name": "database", + "registry_id": "244069240907", + "repository_url": "244069240907.dkr.ecr.us-east-1.amazonaws.com/database", + "tags": null, + "tags_all": {}, + "timeouts": null + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiZGVsZXRlIjoxMjAwMDAwMDAwMDAwfX0=" + } + ] + }, + { + "mode": "managed", + "type": "aws_security_group", + "name": "docker_sg", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:security-group/sg-07ccce6631c3ec977", + "description": "Security group for Docker Compose app", + "egress": [ + { + "cidr_blocks": [ + "0.0.0.0/0" + ], + "description": "", + "from_port": 0, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "-1", + "security_groups": [], + "self": false, + "to_port": 0 + } + ], + "id": "sg-07ccce6631c3ec977", + "ingress": [ + { + "cidr_blocks": [ + "10.0.0.0/16" + ], + "description": "", + "from_port": 3306, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 3306 + }, + { + "cidr_blocks": [ + "10.0.0.0/16" + ], + "description": "", + "from_port": 5000, + "ipv6_cidr_blocks": [], + "prefix_list_ids": [], + "protocol": "tcp", + "security_groups": [], + "self": false, + "to_port": 5000 + } + ], + "name": "docker_security_group", + "name_prefix": "", + "owner_id": "244069240907", + "revoke_rules_on_delete": false, + "tags": { + "Environment": "dev", + "Terraform": "true" + }, + "tags_all": { + "Environment": "dev", + "Terraform": "true" + }, + "timeouts": null, + "vpc_id": "vpc-0c375df36a4e25b86" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6OTAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIxIn0=", + "dependencies": [ + "data.aws_vpc.default" + ] + } + ] + }, + { + "mode": "managed", + "type": "aws_subnet", + "name": "this", + "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]", + "instances": [ + { + "schema_version": 1, + "attributes": { + "arn": "arn:aws:ec2:us-east-1:244069240907:subnet/subnet-09d1b4944d86dfd07", + "assign_ipv6_address_on_creation": false, + "availability_zone": "us-east-1f", + "availability_zone_id": "use1-az5", + "cidr_block": "172.31.128.0/20", + "customer_owned_ipv4_pool": "", + "enable_dns64": false, + "enable_resource_name_dns_a_record_on_launch": false, + "enable_resource_name_dns_aaaa_record_on_launch": false, + "id": "subnet-09d1b4944d86dfd07", + "ipv6_cidr_block": "", + "ipv6_cidr_block_association_id": "", + "ipv6_native": false, + "map_customer_owned_ip_on_launch": false, + "map_public_ip_on_launch": true, + "outpost_arn": "", + "owner_id": "244069240907", + "private_dns_hostname_type_on_launch": "ip-name", + "tags": { + "Name": "Public Subnet" + }, + "tags_all": { + "Name": "Public Subnet" + }, + "timeouts": null, + "vpc_id": "vpc-0c375df36a4e25b86" + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMH0sInNjaGVtYV92ZXJzaW9uIjoiMSJ9", + "dependencies": [ + "data.aws_vpc.default" + ] + } + ] + } + ], + "check_results": null +} From c4c640c48ddf924bffdb3f40c4c093df3abddf34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CChathumiii=E2=80=9D?= <“chathumirambukwella@gmail.com”> Date: Thu, 9 Mar 2023 03:32:22 +0000 Subject: [PATCH 02/16] Added db Dockerfile --- db/Dockerfile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/Dockerfile diff --git a/db/Dockerfile b/db/Dockerfile new file mode 100644 index 0000000..d63a577 --- /dev/null +++ b/db/Dockerfile @@ -0,0 +1,15 @@ +# Use an official MySQL runtime as a parent image +FROM mysql:latest + +# Set the working directory to /app +WORKDIR /app + +# Copy the SQL script to create the database and table into the container +COPY ./init.sql /docker-entrypoint-initdb.d/ + +# Set environment variables +ENV MYSQL_ROOT_PASSWORD=password +ENV MYSQL_DATABASE=knights + +# Expose port 3306 for MySQL connections +EXPOSE 5000 \ No newline at end of file From 3dc1a0236766e948d2923d1f4744834192a18c3f Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:29:01 -0400 Subject: [PATCH 03/16] Create main.yml --- .github/workflows/main.yml | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..a7c10db --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,54 @@ +name: Deploy to ECR + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + + build: + + name: Build Image + runs-on: ubuntu-latest + + steps: + + - name: Check out code + uses: actions/checkout@v2 + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} + AWS_REGION: us-east-1 + + - name: Build, test, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: application + IMAGE_TAG: latest + run: | + cd app + + #Docker build + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: Build, test, tag, and push image to Amazon ECR + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: database + IMAGE_TAG: latest + run: | + cd db + #Docker build + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From d66517c68302da3e9366ac3eec32e28b2b44af0c Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:33:44 -0400 Subject: [PATCH 04/16] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a7c10db..f77ec80 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,10 @@ name: Deploy to ECR on: push: branches: - - main + - master pull_request: branches: - - main + - master jobs: From 3a6c51ff63d903d1234c11199f15d5b60276492f Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:36:30 -0400 Subject: [PATCH 05/16] Update main.yml --- .github/workflows/main.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f77ec80..9864b81 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Deploy to ECR +name: Deploy to Amazon ECR on: push: @@ -9,46 +9,41 @@ on: - master jobs: - build: - - name: Build Image + name: Build and Push Docker Images runs-on: ubuntu-latest steps: - - - name: Check out code + - name: Checkout Code uses: actions/checkout@v2 - + - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 + with: + registry: 'aws-account-id.dkr.ecr.us-east-1.amazonaws.com' + region: 'us-east-1' env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} - AWS_REGION: us-east-1 - - name: Build, test, tag, and push image to Amazon ECR + - name: Build and Push App Docker Image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: application IMAGE_TAG: latest run: | cd app - - #Docker build docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - - name: Build, test, tag, and push image to Amazon ECR + - name: Build and Push Database Docker Image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: database IMAGE_TAG: latest run: | cd db - #Docker build docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG From bcb1b0fd0818a9fda1d428514f31bafdff10b675 Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:41:43 -0400 Subject: [PATCH 06/16] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9864b81..6ebfcd8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -32,7 +32,7 @@ jobs: env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: application - IMAGE_TAG: latest + IMAGE_TAG: v1.0 run: | cd app docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . @@ -42,7 +42,7 @@ jobs: env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: database - IMAGE_TAG: latest + IMAGE_TAG: v1.0 run: | cd db docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . From 4b19779e3af175e5f39161ed42f6deba8d218beb Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:51:41 -0400 Subject: [PATCH 07/16] Update main.yml --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ebfcd8..8694e87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,6 +27,7 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} + AWS_REGION: us-east-1 - name: Build and Push App Docker Image to Amazon ECR env: From 5065b4f8bd47cd9865520e89058701f484acdc30 Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:53:37 -0400 Subject: [PATCH 08/16] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8694e87..6e4035a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: registry: 'aws-account-id.dkr.ecr.us-east-1.amazonaws.com' region: 'us-east-1' env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} AWS_REGION: us-east-1 From 3fd84280b9a000c927d130bf824bf95a6d2e000e Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Sun, 12 Mar 2023 17:55:30 -0400 Subject: [PATCH 09/16] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6e4035a..85346e9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,12 +24,12 @@ jobs: registry: 'aws-account-id.dkr.ecr.us-east-1.amazonaws.com' region: 'us-east-1' env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} AWS_REGION: us-east-1 - - name: Build and Push App Docker Image to Amazon ECR + - name: Build and Push Application Docker Image to Amazon ECR env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} ECR_REPOSITORY: application From e95a6ccdaa1e2f74fb494614608c40fa5c946e10 Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:52:31 -0400 Subject: [PATCH 10/16] Update app.py --- app/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 34356b0..66964d9 100644 --- a/app/app.py +++ b/app/app.py @@ -30,4 +30,4 @@ def index() -> str: if __name__ == '__main__': - app.run(host='0.0.0.0') + app.run(host='0.0.0.0', port=5000, debug=True) From 4bf59f5798c99080eb321bb32470533c82b45efb Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 15:53:59 -0400 Subject: [PATCH 11/16] Update app.py --- app/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 66964d9..34356b0 100644 --- a/app/app.py +++ b/app/app.py @@ -30,4 +30,4 @@ def index() -> str: if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000, debug=True) + app.run(host='0.0.0.0') From e79bde15f6cd09a2d440e1caeed310e095e82321 Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 17:41:27 -0400 Subject: [PATCH 12/16] Update securitygroup.tf --- terraform/securitygroup.tf | 42 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/terraform/securitygroup.tf b/terraform/securitygroup.tf index fa008b3..68970b4 100644 --- a/terraform/securitygroup.tf +++ b/terraform/securitygroup.tf @@ -3,29 +3,39 @@ resource "aws_security_group" "docker_sg" { description = "Security group for Docker Compose app" vpc_id = data.aws_vpc.default.id + ingress { + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } ingress { - from_port = 5000 - to_port = 5000 - protocol = "tcp" - cidr_blocks = ["10.0.0.0/16"] + from_port = 5001 + to_port = 5001 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] } - ingress { - from_port = 3306 - to_port = 3306 - protocol = "tcp" - cidr_blocks = ["10.0.0.0/16"] + from_port = 5002 + to_port = 5002 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + from_port = 5003 + to_port = 5003 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] } - egress { - from_port = 0 - to_port = 0 - protocol = "-1" - cidr_blocks = ["0.0.0.0/0"] + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] } - tags = { +tags = { Terraform = "true" Environment = "dev" } -} \ No newline at end of file +} From 3ac6cb343af8194ba1191645a8a0ddd23247b06d Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 22:46:56 -0400 Subject: [PATCH 13/16] Update Dockerfile --- db/Dockerfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/db/Dockerfile b/db/Dockerfile index d63a577..4371928 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -7,9 +7,5 @@ WORKDIR /app # Copy the SQL script to create the database and table into the container COPY ./init.sql /docker-entrypoint-initdb.d/ -# Set environment variables -ENV MYSQL_ROOT_PASSWORD=password -ENV MYSQL_DATABASE=knights - # Expose port 3306 for MySQL connections -EXPOSE 5000 \ No newline at end of file +EXPOSE 5000 From 653a9ee4b9b433f39b5cb651502bdc1d92e9bb32 Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 22:47:25 -0400 Subject: [PATCH 14/16] Update app.py --- app/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index 34356b0..66964d9 100644 --- a/app/app.py +++ b/app/app.py @@ -30,4 +30,4 @@ def index() -> str: if __name__ == '__main__': - app.run(host='0.0.0.0') + app.run(host='0.0.0.0', port=5000, debug=True) From 952d259326e26aeed8b37472e8989aa58ea435aa Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:17:20 -0400 Subject: [PATCH 15/16] Update Dockerfile --- db/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/Dockerfile b/db/Dockerfile index 4371928..26c96c3 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -8,4 +8,4 @@ WORKDIR /app COPY ./init.sql /docker-entrypoint-initdb.d/ # Expose port 3306 for MySQL connections -EXPOSE 5000 +EXPOSE 3306 From d06d76b8286b0a84b20a58ea77938862b5b564ca Mon Sep 17 00:00:00 2001 From: Chathumi Rambukwella <61647996+Chathumiii@users.noreply.github.com> Date: Mon, 13 Mar 2023 23:29:51 -0400 Subject: [PATCH 16/16] Update Dockerfile --- db/Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/db/Dockerfile b/db/Dockerfile index 4371928..2008534 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -2,10 +2,10 @@ FROM mysql:latest # Set the working directory to /app -WORKDIR /app +COPY ./init.sql /tmp # Copy the SQL script to create the database and table into the container -COPY ./init.sql /docker-entrypoint-initdb.d/ +CMD [ "mysqld", "--init-file=/tmp/init.sql" ] + + -# Expose port 3306 for MySQL connections -EXPOSE 5000