I am working on a Java Spring Boot project, and I am having problems when using GitHub Actions for CD.
I was able to run my test code and the entire application successfully on my local machine. However, when I execute the deployment workflow using GitHub Actions to deploy the application to an EC2 (Ubuntu) instance, the test code step fails with an error.
I suspect that the issue might be related to a recent change (.env) I made.
The format of the .env file is as follows.
DB_HOST=localhost DB_PORT=3306 DB_USERNAME=root DB_PASSWORD=1234
To avoid exposing sensitive information, I created a .env file inside the resources folder and added it to .gitignore, so it doesn’t get pushed to GitHub.
To ensure the application runs properly during deployment, I stored the environment variable which is same as my local .env file values as GitHub secrets. During the workflow execution, before running the application, I recreate the .env file in the resources folder with the values from GitHub secrets.
Since implementing this change, I’ve been encountering test failures in the GitHub Actions workflow, but I’m not sure why.
How can I resolve this issue?
Below is my workflow script: `name: CD to EC2
on: push: branches: - main
jobs: Deploy: runs-on: ubuntu-latest steps: - name: Access EC2 by SSH Key uses: appleboy/[email protected] with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
script_stop: true
script: |
cd /home/ubuntu/SignUp
git pull origin main
touch src/main/resources/.env
echo ${{ secrets.ENV_VARIABLES }} > src/main/resources/.env
./gradlew clean build
sudo fuser -k -n tcp 8080 || true
nohup java -jar build/libs/*SNAPSHOT.jar > ./output.log 2>&1 &`
Thanks in advance for your help!
I expected the CD process by github actions to work well.