Skip to content

Commit

Permalink
Create aws.yml (#48)
Browse files Browse the repository at this point in the history
* Create aws.yml

* Update aws.yml

* Create .aws.task-definition.json

* Update aws.yml

* Update aws.yml

* Update aws.yml

* mv task definition JSON

* Update aws.yml

* mv task def

* rename task def

* Update task-definition.json

* Update task-definition.json

* Update aws.yml & task-definition.json

* Update aws.yml

* Update Dockerfile

* Update task-definition.json

with EntryPoint

* Update task-definition.json

* Update aws.yml

* Update aws.yml

* Update Dockerfile

* Update aws.yml & task-definition.json

* Update aws.yml & task-definition.json

* Update aws.yml & task-definition.json

* Update aws.yml & task-definition.json

* Update task-definition.json

* Update Dockerfile & task-definition.json

* Update Dockerfile & task-definition.json

* Update Dockerfile & task-definition.json

* Update task-definition.json

* Update aws.yml

* Update aws.yml

* Attempt new conf

* Attempt conf fix

* Revert changes

* Update task-definition.json

* Update task-definition.json

* Update task-definition.json

* Update run.sh & Dockerfile

* Update run.sh & Dockerfile

* Update Dockerfile

* Update run.sh & Dockerfile

* Update Dockerfile

* Update Dockerfile, aws.yml & docker-image.yml

* Update Dockerfile

* Update Dockerfile

* Update prot references

* Update .aws/task-definition.json

* Update task-definition.json

* Update task-definition.json

* Update ports

* Update .aws/task-definition.json

* Update port refs

* Update Dockerfile

* Update aws.yml & README.md
  • Loading branch information
conorheffron authored Sep 9, 2024
1 parent ecd5dc5 commit 4eb373b
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 25 deletions.
90 changes: 90 additions & 0 deletions .aws/task-definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"taskDefinitionArn": "arn:aws:ecs:eu-north-1:345594590074:task-definition/ironoc:latest",
"containerDefinitions": [
{
"name": "ironoc",
"image": "345594590074.dkr.ecr.eu-north-1.amazonaws.com/conorheffron/ironoc:latest",
"memory": "512",
"portMappings": [
{
"name": "ironoc-80-tcp",
"containerPort": 8080,
"hostPort": 80,
"protocol": "tcp",
"appProtocol": "http"
}
],
"essential": true,
"environment": [],
"mountPoints": [],
"volumesFrom": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/ironoc",
"mode": "non-blocking",
"awslogs-create-group": "true",
"max-buffer-size": "25m",
"awslogs-region": "eu-north-1",
"awslogs-stream-prefix": "ecs"
}
},
"systemControls": []
}
],
"family": "ironoc",
"taskRoleArn": "arn:aws:iam::345594590074:role/ecsTaskExecutionRole",
"executionRoleArn": "arn:aws:iam::345594590074:role/ecsTaskExecutionRole",
"networkMode": "bridge",
"volumes": [],
"status": "ACTIVE",
"requiresAttributes": [
{
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"name": "ecs.capability.execution-role-awslogs"
},
{
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.28"
},
{
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"name": "ecs.capability.task-eni"
},
{
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.29"
}
],
"placementConstraints": [],
"compatibilities": [
"EC2",
"FARGATE"
],
"requiresCompatibilities": [
"EC2"
],
"cpu": null,
"memory": null,
"runtimePlatform": {
"cpuArchitecture": "X86_64",
"operatingSystemFamily": "LINUX"
},
"registeredAt": "2024-09-08T21:13:30.158Z",
"registeredBy": "arn:aws:iam::345594590074:root",
"tags": []
}
75 changes: 75 additions & 0 deletions .github/workflows/aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Deploy to Amazon ECS

on:
push:
branches: [ "main" ]

env:
AWS_REGION: eu-north-1
ECR_REPOSITORY: conorheffron/ironoc
ECS_SERVICE: IronocService
ECS_CLUSTER: IronocPortfolioCluster
ECS_TASK_DEFINITION: .aws/task-definition.json
CONTAINER_NAME: ironoc

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
18 changes: 0 additions & 18 deletions .github/workflows/docker-image.yml

This file was deleted.

12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM eclipse-temurin:21-jdk

VOLUME /tmp
#for local
#ADD target/*.war app.war
#for CI/CD
ADD *.war app.war

COPY target/*.war app.war
RUN sh -c 'touch /app.war'

ENV RUN_FILE /run.sh
ADD run.sh ${RUN_FILE}
COPY run.sh ${RUN_FILE}
RUN chmod +x ${RUN_FILE}

ENTRYPOINT [ "sh", "-c", "${RUN_FILE}" ]
EXPOSE 8080

ENTRYPOINT [ "sh", "-c", "${RUN_FILE}" ]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

![Auto Assign](https://github.com/conorheffron/ironoc/actions/workflows/auto-assign.yml/badge.svg)

[![Deploy to Amazon ECS](https://github.com/conorheffron/ironoc/actions/workflows/aws.yml/badge.svg)](https://github.com/conorheffron/ironoc/actions/workflows/aws.yml)

# Docker Image
[ironoc Docker Hub Link](https://hub.docker.com/repository/docker/conorheffron/ironoc/general)

Expand All @@ -14,7 +16,7 @@
Personal website / portfolio http://www.ironoc.com/ (no longer hosted)

# Tech Stack
Java 21 (LTS), Spring Boot 3.3, Maven 3.8, HTML5+CSS, JQuery, Docker / Bash
Java 21 (LTS), Spring Boot 3.3, Maven 3.8, HTML5+CSS, JQuery, Docker / Bash, AWS

# Run without cloning project:
```
Expand Down

0 comments on commit 4eb373b

Please sign in to comment.