-
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
53 additions
and
69 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 |
---|---|---|
@@ -1,96 +1,80 @@ | ||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle | ||
|
||
name: Java CI with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
branches: ["main"] | ||
pull_request: | ||
branches: [ "main" ] | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
- name: Copy application.properties into runner | ||
run: | | ||
mkdir -p ./src/main/resources | ||
touch ./src/main/resources/application.properties | ||
echo "${{secrets.APPLICATION_YML}}" > ./src/main/resources/application.properties | ||
- name: Copy application.properties into runner | ||
run: | | ||
mkdir -p ./src/main/resources | ||
touch ./src/main/resources/application.properties | ||
echo "${{secrets.APPLICATION_YML}}" > ./src/main/resources/application.properties | ||
- name: Build with Gradle | ||
run: | | ||
chmod +x gradlew | ||
./gradlew build | ||
- name: Build with Gradle | ||
run: | | ||
chmod +x gradlew | ||
./gradlew build | ||
- name: Docker Login | ||
# You may pin to the exact commit or the version. | ||
# uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 | ||
uses: docker/[email protected] | ||
with: | ||
# Server address of Docker registry. If not set then will default to Docker Hub | ||
registry: ghcr.io | ||
# Username used to log against the Docker registry | ||
username: ${{ secrets.GHCR_USERNAME }} | ||
# Password or personal access token used to log against the Docker registry | ||
password: ${{ secrets.GHCR_PASSWORD }} | ||
- name: Docker Login | ||
uses: docker/[email protected] | ||
with: | ||
registry: ghcr.io | ||
username: ${{ secrets.GHCR_USERNAME }} | ||
password: ${{ secrets.GHCR_PASSWORD }} | ||
|
||
- name: Build Docker | ||
run: | | ||
docker build -t ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest . | ||
- name: Build Docker | ||
run: | | ||
docker build -t ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest . | ||
- name: Push Docker | ||
run: docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest | ||
- name: Push Docker | ||
run: docker push ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest | ||
|
||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
needs: build | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Copy docker-compose into instance | ||
uses: appleboy/scp-action@master #이미 존재하는 경우 덮어씀 | ||
with: | ||
host: ${{secrets.GCP_HOST}} | ||
username: ${{secrets.GCP_USERNAME}} | ||
key: ${{secrets.GCP_PRIVATEKEY}} | ||
source: "./docker-compose.yml" | ||
target: "/home/${{secrets.GCP_USERNAME}}" | ||
strip_components: 3 | ||
overwrite: true | ||
debug: true | ||
|
||
|
||
- name: Copy docker-compose into instance | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.GCP_HOST }} | ||
username: ${{ secrets.GCP_USERNAME }} | ||
key: ${{ secrets.GCP_PRIVATEKEY }} | ||
source: "./docker-compose.yml" | ||
target: "/home/${{ secrets.GCP_USERNAME }}" | ||
strip_components: 3 | ||
overwrite: true | ||
debug: true | ||
|
||
- name: Deploy to Instance | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{secrets.GCP_HOST}} | ||
username: ${{secrets.GCP_USERNAME}} | ||
key: ${{secrets.GCP_PRIVATEKEY}} | ||
script: | | ||
sudo docker login -u ${{ secrets.GHCR_USERNAME }} -p ${{ secrets.GHCR_PASSWORD }} | ||
sudo docker pull ${{ secrets.GHCR_USERNAME }}/ssock:latest | ||
sudo docker rm -f $(docker ps -qa) 2>/dev/null || true | ||
cd /home/${{secrets.GCP_USERNAME}} | ||
sudo docker-compose up -d | ||
sudo docker image prune -f | ||
- name: Deploy to Instance | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.GCP_HOST }} | ||
username: ${{ secrets.GCP_USERNAME }} | ||
key: ${{ secrets.GCP_PRIVATEKEY }} | ||
script: | | ||
echo ${{ secrets.GHCR_PASSWORD }} | sudo docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin | ||
sudo docker pull ghcr.io/${{ secrets.GHCR_USERNAME }}/ssock:latest | ||
sudo docker rm -f $(sudo docker ps -qa) || true | ||
cd /home/${{ secrets.GCP_USERNAME }} | ||
sudo docker-compose up -d | ||
sudo docker image prune -f |