diff --git a/.github/workflows/Docker-Image CI.yml b/.github/workflows/Docker-Image CI.yml new file mode 100644 index 0000000..5031fee --- /dev/null +++ b/.github/workflows/Docker-Image CI.yml @@ -0,0 +1,36 @@ +name: spring-boot Docker Image CI for ECS +on: + push: + branches: [ master ] + workflow_dispatch: + + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + push: true + file: Dockerfile + tags: ${{ secrets.DOCKERHUB_USERNAME }}/spring-boot:ECS-v${{ github.run_number }} + - + name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..62ee695 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,34 @@ +name: nginx Docker Image CI for ECS +on: + workflow_dispatch: + + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + platforms: linux/amd64 + push: true + file: docker/nginx/Dockerfile.nginx.NoSSl + tags: ${{ secrets.DOCKERHUB_USERNAME }}/java-nginx:ECS-v${{ github.run_number }} + - + name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + diff --git a/.gitignore b/.gitignore index ff29930..881ccf4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ dist/ nbdist/ .nb-gradle/ .elasticbeanstalk + +### remove GitPod file ### +*.local \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08d97aa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM maven:3.8.3-jdk-11 AS maven_build +WORKDIR /tmp +COPY pom.xml . +COPY src/ ./src/ +RUN mvn package -Dmaven.test.skip=true + +FROM openjdk:11 +COPY --from=maven_build /tmp/target/easy-notes-1.0.0.jar /data/easy-notes-1.0.0.jar +EXPOSE 8080 +CMD java -jar /data/easy-notes-1.0.0.jar \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a173770 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3" +services: + app: + image: spring-boot:latest + restart: always + ports: + - 8080:8080 + depends_on: + - db + db: + image: mysql:5 + restart: always + expose: + - 3306 + environment: + - MYSQL_ROOT_PASSWORD=supersecretpassword + - MYSQL_DATABASE=notes_app + - MYSQL_USER=app + - MYSQL_PASSWORD=secretpassword + nginx: + image: java-nginx:ECS-v1 + restart: always + ports: + - 80:80 + depends_on: + - app \ No newline at end of file diff --git a/docker/nginx/Dockerfile.nginx.NoSSl b/docker/nginx/Dockerfile.nginx.NoSSl new file mode 100644 index 0000000..b4e61ed --- /dev/null +++ b/docker/nginx/Dockerfile.nginx.NoSSl @@ -0,0 +1,2 @@ +FROM nginx:alpine +COPY docker/nginx/default.conf.NoSSL /etc/nginx/conf.d/default.conf diff --git a/docker/nginx/Dockerfile.nginx.SSL b/docker/nginx/Dockerfile.nginx.SSL new file mode 100644 index 0000000..171674f --- /dev/null +++ b/docker/nginx/Dockerfile.nginx.SSL @@ -0,0 +1,2 @@ +FROM nginx:alpine +COPY docker/nginx/default.conf.SSL /etc/nginx/conf.d/default.conf diff --git a/docker/nginx/default.conf.NoSSL b/docker/nginx/default.conf.NoSSL new file mode 100644 index 0000000..9a291ac --- /dev/null +++ b/docker/nginx/default.conf.NoSSL @@ -0,0 +1,19 @@ +server { + listen 80; + server_name devops.aurigastore.com; + server_tokens off; + client_max_body_size 20M; + + location / { + try_files $uri @proxy_api; + } + + location @proxy_api { + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Url-Scheme $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://java-app.service.com:8080; + } +} \ No newline at end of file diff --git a/docker/nginx/default.conf.SSL b/docker/nginx/default.conf.SSL new file mode 100644 index 0000000..91e8d85 --- /dev/null +++ b/docker/nginx/default.conf.SSL @@ -0,0 +1,33 @@ +server { + listen 80; + server_name _; + server_tokens off; + client_max_body_size 20M; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + location /api { + try_files $uri @proxy_api; + } + location /admin { + try_files $uri @proxy_api; + } + + location @proxy_api { + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Url-Scheme $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://backend:8000; + } + + location /django_static/ { + autoindex on; + alias /app/backend/server/django_static/; + } +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index d357d46..327ae44 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,7 +1,7 @@ ## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) -spring.datasource.url = jdbc:mysql://localhost:3306/notes_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false -spring.datasource.username = root -spring.datasource.password = callicoder +spring.datasource.url = jdbc:mysql://mysql-db.service.com:3306/notes_app?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false +spring.datasource.username = app +spring.datasource.password = secretpassword ## Hibernate Properties @@ -10,4 +10,4 @@ spring.datasource.password = callicoder spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect # Hibernate ddl auto (create, create-drop, validate, update) -spring.jpa.hibernate.ddl-auto = update \ No newline at end of file +spring.jpa.hibernate.ddl-auto = update diff --git a/task-definitions/app-task-definition.json b/task-definitions/app-task-definition.json new file mode 100644 index 0000000..2693067 --- /dev/null +++ b/task-definitions/app-task-definition.json @@ -0,0 +1,51 @@ +{ + "requiresCompatibilities": [ + "FARGATE" + ], + "inferenceAccelerators": [], + "containerDefinitions": [ + { + "name": "app", + "image": "rajneeshmehta93/spring-boot:ECS-v4", + "memoryReservation": "128", + "resourceRequirements": null, + "essential": true, + "portMappings": [ + { + "containerPort": "8080", + "protocol": "tcp" + } + ], + "environment": null, + "environmentFiles": [], + "secrets": null, + "mountPoints": null, + "volumesFrom": null, + "hostname": null, + "user": null, + "workingDirectory": null, + "extraHosts": null, + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/spring-boot-app", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "ecs" + } + }, + "ulimits": null, + "dockerLabels": null, + "dependsOn": null, + "repositoryCredentials": { + "credentialsParameter": "" + } + } + ], + "volumes": [], + "networkMode": "awsvpc", + "memory": "512", + "cpu": "256", + "executionRoleArn": "arn:aws:iam::597927635090:role/ecsTaskExecutionRole", + "family": "spring-boot-app", + "tags": [] +} \ No newline at end of file diff --git a/task-definitions/db-task-definition.json b/task-definitions/db-task-definition.json new file mode 100644 index 0000000..f3b0af6 --- /dev/null +++ b/task-definitions/db-task-definition.json @@ -0,0 +1,68 @@ +{ + "requiresCompatibilities": [ + "FARGATE" + ], + "inferenceAccelerators": [], + "containerDefinitions": [ + { + "name": "db", + "image": "mysql:5", + "memoryReservation": "128", + "resourceRequirements": null, + "essential": true, + "portMappings": [ + { + "containerPort": "3306", + "protocol": "tcp" + } + ], + "environment": [ + { + "name": "MYSQL_ROOT_PASSWORD", + "value": "supersecretpassword" + }, + { + "name": "MYSQL_DATABASE", + "value": "notes_app" + }, + { + "name": "MYSQL_USER", + "value": "app" + }, + { + "name": "MYSQL_PASSWORD", + "value": "secretpassword" + } + ], + "environmentFiles": [], + "secrets": null, + "mountPoints": null, + "volumesFrom": null, + "hostname": null, + "user": null, + "workingDirectory": null, + "extraHosts": null, + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/spring-boot-db", + "awslogs-region": "us-east-1", + "awslogs-stream-prefix": "ecs" + } + }, + "ulimits": null, + "dockerLabels": null, + "dependsOn": null, + "repositoryCredentials": { + "credentialsParameter": "" + } + } + ], + "volumes": [], + "networkMode": "awsvpc", + "memory": "512", + "cpu": "256", + "executionRoleArn": "arn:aws:iam::597927635090:role/ecsTaskExecutionRole", + "family": "spring-boot-db", + "tags": [] +} \ No newline at end of file