Skip to content

Commit a5514d2

Browse files
committed
maven.yml 수정
1 parent 261a04f commit a5514d2

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

.github/workflows/maven.yml

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,57 @@
1-
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
9-
name: Java CI with Maven
1+
name: CI/CD with Maven and Docker
102

113
on:
124
push:
135
branches: [ "master" ]
14-
pull_request:
15-
branches: [ "master" ]
166

177
jobs:
18-
build:
19-
8+
build-and-deploy:
209
runs-on: ubuntu-latest
2110

11+
env:
12+
IMAGE_NAME: jermany17/another-web-project
13+
2214
steps:
23-
- uses: actions/checkout@v4
24-
- name: Set up JDK 17
25-
uses: actions/setup-java@v4
26-
with:
27-
java-version: '17'
28-
distribution: 'temurin'
29-
cache: maven
30-
- name: Build with Maven
31-
run: mvn -B package --file pom.xml
32-
33-
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
34-
- name: Update dependency graph
35-
uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
15+
- name: Checkout source
16+
uses: actions/checkout@v4
17+
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v4
20+
with:
21+
java-version: '21'
22+
distribution: 'temurin'
23+
cache: maven
24+
25+
- name: Build JAR with Maven Wrapper
26+
run: ./mvnw package -DskipTests
27+
28+
- name: Set up Docker
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Login to DockerHub
32+
uses: docker/login-action@v3
33+
with:
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
37+
- name: Build Docker image with short commit SHA
38+
run: |
39+
VERSION=$(echo "${{ github.sha }}" | cut -c1-7)
40+
docker build -t $IMAGE_NAME:$VERSION .
41+
echo "VERSION=$VERSION" >> $GITHUB_ENV
42+
43+
- name: Push Docker image
44+
run: |
45+
docker push $IMAGE_NAME:${{ env.VERSION }}
46+
47+
- name: Deploy to EC2 via SSH
48+
uses: appleboy/ssh-action@v1.0.3
49+
with:
50+
host: ${{ secrets.EC2_HOST }}
51+
username: ubuntu
52+
key: ${{ secrets.EC2_SSH_KEY }}
53+
script: |
54+
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
55+
docker pull $IMAGE_NAME:${{ env.VERSION }}
56+
docker stop app || true && docker rm app || true
57+
docker run -d --name app --env-file .env -p 8080:8080 $IMAGE_NAME:${{ env.VERSION }}

0 commit comments

Comments
 (0)