AWS Various Deployment Methods
1. Non-disruptive deployment using Github Action
Instead of manual distribution, distribution was carried out to enable Github Action, CI, and CD for automatic build.
What is CI & CD?
CI/CD is a method that helps developers develop and deploy applications faster. CI continuously integrates and builds code changes, while CD continuously deploys. This allows developers to get faster feedback and maintain and improve the quality of their applications.
Github Action Settings
Github Action for automatic build was set up as a CI/CD tool. This is because version management is already set to Github, and some parts of Travis were inaccessible as it was changed to a paid version.
If you write .yml```` for operation in the Actions tab, the file will be created in the .github/workflowslocation. And check whether the build is successful. Currently, building is possible even when the test fails with--exclude-task test```.
name: BoardApi CI/CD
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build --exclude-task testAnd to use AWS, register AWS ACCESS KEY ID and SECRET KEY in the relevant repo settings Actions secrets and variables.
Jenkins, differences from Travis
GitHub Actions#### is a built-in CI/CD tool that comes with GitHub. It's easy to set up and use, and can be integrated with various GitHub features. It's best suited for small to medium-sized GitHub projects.
Jenkins#### is a popular open source CI/CD tool that has been around for many years. It is very flexible and can be used with a variety of programming languages and tools. Best suited for large, complex projects that require a lot of customization.
Travis CI#### is a cloud-based CI/CD tool specialized for GitHub projects. It's easy to set up and use, and can be integrated with various GitHub features. It's best suited for small to medium-sized GitHub projects.
#### Creating S3 I chose the region I needed and didn't use versioning because I didn't need it. And since we are using an accessible IAM user, select Block all public access.
#### EC2 Configuration Proceed with EC2 basic environment settings. The specifications of the instance I created were set to Ubuntu 22.04 LTS, t2.micro (free tier), 30GiB storage. For security, an IAM role is granted to enable full access to S3 and Codedeploy. From the EC2 console, install the JDK and [Amazon correto](https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/downloads-list.html) that matches your project JDK. ``` $ sudo apt update $ sudo apt-get install openjdk-17-jdk $ sudo wget https://corretto.aws/downloads/latest/amazon-corretto-17-x64-linux-jdk.tar.gz ``` Set environment variables in the last line of ```/etc/profile```. ``` $ sudo nano /etc/profile $ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 $ export PATH=$JAVA_HOME/bin/:$PATH $ export CLASS_PATH=$JAVA_HOME/lib:$CLASS_PATH $ sudo reboot now ``` View the guide [Installing the CodeDeploy Agent for Ubuntu Server](https://docs.aws.amazon.com/ko_kr/codedeploy/latest/userguide/codedeploy-agent-operations-install-ubuntu.html) and install the agent. If the status is active, success! ``` $ sudo apt install ruby $ cd /home/ubuntu $ wget https://aws-codedeploy-ap-northeast-2.s3.ap-northeast-2.amazonaws.com/latest/install $ chmod +x ./install $ sudo ./install auto $ sudo service codedeploy-agent status ``` #### Change Github Action settings Edit the ```env``` and ```jobs``` details in the .yml file created earlier. The order of progress after push is as follows. 1. Set up JDK 17 2. Grant execute permission for gradlew 3. Build with Gradle 4. Make Zip File 5. Configure AWS credentials 6. Upload to S3 7. Code Deployment Each part of the logic was created by referring to [cicd open source](https://github.com/kbsat/cicdproject).
#### Create appspec.yml file Create an ``appspec.yml``` file for CodeDeploy operation. The CodeDeploy agent determines where to download the download code and where to store the code on the EC2 server. ````afterinstall```` is a section in a deployment script that contains a list of commands or scripts that should be run after the installation process is complete. In the example, the afterinstall section contains a hook named AfterInstall. This hook specifies the location of the scripts/deploy.sh shell script, which runs with a timeout of 60 seconds and runs as the ubuntu user. ```yml version: 0.0 os: ubuntu files: - source: / destination: /home/ubuntu/boardApi permissions: - object: /home/ubuntu/boardApi/ owner: ubuntu group: ubuntu hooks: AfterInstall: - location: scripts/deploy.sh timeout: 60 runas: ubuntu ```
#### Shell script for deployment Run the built jar file, and if it is already running, set it to run as the newly built jar file. ``` #!/usr/bin/env bash REPOSITORY=/home/ubuntu/boardApi cd $REPOSITORY APP_NAME=boardApi JAR_NAME=$(ls $REPOSITORY/build/libs/ | grep 'SNAPSHOT.jar' | tail -n 1) JAR_PATH=$REPOSITORY/build/libs/$JAR_NAME CURRENT_PID=$(pgrep -f $APP_NAME) if [ -z $CURRENT_PID ] then echo ">Nothing to quit." else echo "> kill -9 $CURRENT_PID" kill -15 $CURRENT_PID sleep 5 fi echo "> Deploy $JAR_PATH" nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null & ``` ```nohup java -jar $JAR_PATH > /dev/null 2> /dev/null < /dev/null &``` 부분은 무중단으로 실행하고자 할 때 ```nohup```을 적용하는 부분이라 git clone으로 .jar 파일 배포 방식(이하 포스팅 됨)과 유사한 것을 볼 수 있었습니다.
### 2. Manual deployment using Git clone This is a method of downloading the source directly from Github and running it on EC2. It has the advantage of being able to easily connect to AWS instances without using a separate program. To connect to Github where the source code is located on an EC2 instance, you must create an ssh key and register the public key on Github. ``` ssh-keygen -t rsa -C github account email (example@github.com) ``` Register the key obtained through the following command in ```SSH and GPG keys``` in Github settings. ``` cat /home/ubuntu/.ssh/id_rsa ``` Now copy the SSH address of the repo and proceed with clone. ``` git clone {SSH address}(git@github.com:project name.git) ``` Once the source file is received, you can proceed with gradlew build within the project. ``` cd project/build/libs chmod +x gradlew ``` Non-stop distribution is carried out with ``nohup```. At this time, if there is a problem during the deployment process, you can check the error in the ``nohup.out``` file in the same directory as the .jar file. ``` ``` In this case, an issue occurred where ``gradlew build``` resulted in infinite loading due to insufficient memory capacity in Free Tier. [Use Swap memory](https://sundries-in-myidea.tistory.com/102) solved the problem, but it was a cumbersome method because it required manual distribution every time the source code was changed. What is Swap memory? Since RAM memory is insufficient, you can use Linux's HDD space as if it were RAM. This allows you to use the insufficient RAM as if you had expanded it.
### 3. Manual distribution of war file using Filezila You can access the distribution server by setting a private key in Filezila's settings ``SFTP```. When you move a war file to the tomcat or lower webapps posted below, a directory file with the war file name is automatically created. 777 means that the owner, group, and other users all have read, write, and execute permissions. Therefore, this setting is vulnerable in terms of security. Below, permissions were given to the Tomcat user during the tomcat10 setting process, but when transferring files in FileZilla, it was necessary to grant wider permissions, so a temporary setting of ```777``` was set. ``` sudo chmod -R 777 /opt/tomcat/apache-tomcat-10.1.11/webapps ``` Change all owners of the directory and its subdirectories and files to the tomcat user and their groups to the tomcat group. By doing this, the directories and files will belong to the tomcat user and group. ``` sudo chown -R tomcat:tomcat /opt/tomcat/apache-tomcat-10.1.11/webapps ```
Comments
No comments yet. Be the first!
164 posts in 테크
- 2233D Gaussian Splatting vs Unreal Engine: Two Ways to Build a 3D World — and Where Each One Ships
- 222LLMs Inside Unreal Engine: The New Skills Game Developers Need in 2026
- 220Living With Claude Fable 5: How the Most Capable Model Changes the Way You Actually Work
- 219Luma's Bet: From Video Generator to a Single Model That Thinks in Pixels
- 215The Best AI Video Models in 2026: Types, Differences, and Where This Is All Going