Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] CI/CD #10

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/main-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CD

on:
push:
branches: [ "main" ]

jobs:
CI:
runs-on: ubuntu-22.04

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

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'

- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION_MAIN }}" > ./application-main.yml

- name: build with gradle
run: |
chmod +x gradlew
./gradlew clean build -x test

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Login to Docker Hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile-main
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.MAIN_REPONAME }}

CD:
needs: [CI]
runs-on: ubuntu-22.04

steps:
- name: Docker Image Pull and Container Run
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.MAIN_SERVER_HOST }}
username: ${{ secrets.MAIN_USERNAME }}
key: ${{ secrets.MAIN_SERVER_KEY }}
script: |
cd ~
./deploy.sh
29 changes: 29 additions & 0 deletions .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-22.04

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

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'

- name: create secret config file
run: |
cd src/main/resources
echo "${{ secrets.APPLICATION_MAIN }}" > ./application-main.yml

- name: build with gradle
run: |
chmod +x gradlew
./gradlew clean build -x test
9 changes: 9 additions & 0 deletions Dockerfile-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM gradle:8.5-jdk17 AS builder
COPY . /usr/src
WORKDIR /usr/src
RUN gradle wrapper --gradle-version 8.5
RUN ./gradlew clean build -x test

FROM openjdk:17-jdk-alpine
COPY --from=builder /usr/src/build/libs/server-0.0.1-SNAPSHOT.jar /usr/app/app.jar
ENTRYPOINT ["java", "-jar", "/usr/app/app.jar"]
Loading