-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: CI/CD | ||
|
||
on: | ||
push: | ||
branches: [ main, feat/SCRUM-17 ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'corretto' | ||
java-version: '17' | ||
|
||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Make application.yml file | ||
run: | | ||
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run : ./gradlew clean build -x test -Dfile.encoding=UTF-8 | ||
|
||
- name: Docker Login | ||
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build Docker image | ||
run: | | ||
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/timeattack:latest . | ||
- name: Push Docker image to Docker Hub | ||
run: | | ||
docker push ${{ secrets.DOCKER_USERNAME }}/timeattack:latest | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy to Server | ||
uses: appleboy/ssh-action@v0.1.7 | ||
with: | ||
host: ${{ secrets.HOST }} | ||
username: ${{ secrets.USER }} | ||
key: ${{ secrets.SSH_KEY }} | ||
script: | | ||
echo "Pulling latest Docker image..." | ||
docker pull ${{ secrets.DOCKER_USERNAME }}/timeattack:latest | ||
echo "Stopping and removing existing container (if exists)..." | ||
docker stop timeattack || true | ||
docker rm timeattack || true | ||
echo "Running new container..." | ||
docker run -d --name timeattack -p 8080:8080 --restart always ${{ secrets.DOCKER_USERNAME }}/timeattack:latest |