From a19f07bfa63c688bcb8eb2133c437cfa93412760 Mon Sep 17 00:00:00 2001 From: binary-ho Date: Sun, 26 Jan 2025 17:00:57 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20cd=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 83 ++++++++++++++++++++++++++++++++++++ .gitignore | 5 +++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..fdc6cff --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,83 @@ +name: Deploy! + +on: + push: + branches: [ "main" ] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: 11 + cache: 'gradle' + + - name: Build with Gradle + env: + JASYPT_ENCRYPTION_PASSWORD: ${{ secrets.PROPERTY_ENCRYPTION_PASSWORD }} + run: | + chmod +x ./gradlew + ./gradlew clean build --no-build-cache + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USERNAME }} + password: ${{ secrets.GHCR_PASSWORD }} + + - name: Build and push image + run: | + IMAGE="ghcr.io/${{ secrets.GHCR_USERNAME }}" + APP_NAME="imhere-server" + TAG="latest" + + docker build -t $IMAGE/$APP_NAME:$TAG . + docker push $IMAGE/$APP_NAME:$TAG + + # TODO: scp로 docker-compose.yml 전달 + - name: Deploy! + run: | + sudo apt-get update + sudo apt-get install -y curl netcat openssh-client + curl -L "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64" \ + -o /usr/local/bin/cloudflared + chmod +x /usr/local/bin/cloudflared + + nohup cloudflared access tcp \ + --hostname "${{ secrets.SSH_HOST }}" \ + --url "127.0.0.1:2222" \ + --service-token-id "${{ secrets.CLOUDFLARE_TOKEN_ID }}" \ + --service-token-secret "${{ secrets.CLOUDFLARE_TOKEN_SECRET }}" \ + >/tmp/cloudflared.log 2>&1 & + + for i in {1..20}; do + if nc -z 127.0.0.1 2222; then + echo "Connected!" + break + fi + echo "Waiting... ($i/20)" + sleep 1 + done + + echo "${{ secrets.SERVER_SSH_KEY }}" > /tmp/server_key + chmod 600 /tmp/server_key + + ssh -t -o StrictHostKeyChecking=no \ + -i /tmp/server_key \ + -p 2222 \ + ${{ secrets.SERVER_USERNAME }}@127.0.0.1 \ + "cd imhere-server/docker-compose + + docker login ghcr.io -u '${{ secrets.GHCR_USERNAME }}' -p '${{ secrets.GHCR_PASSWORD }}' + + docker-compose down + docker-compose pull + docker-compose up -d --remove-orphans" diff --git a/.gitignore b/.gitignore index f966444..41f8e17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +### Build ### HELP.md .gradle build/ @@ -45,3 +46,7 @@ out/ /src/test/java/gdsc/binaryho/imhere/dev /src/main/java/gdsc/binaryho/imhere/dev /docker-compose** + +### secrets ### +.*secrets +.*env From 671e132d90f6116ff57f8b150db3abca97268837 Mon Sep 17 00:00:00 2001 From: binary-ho Date: Sun, 26 Jan 2025 17:05:11 +0900 Subject: [PATCH 2/5] refactor: upgrade actions/upload-artifact version up to v3 --- .github/workflows/pull-request-gradle-build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-gradle-build-test.yml b/.github/workflows/pull-request-gradle-build-test.yml index 723751b..ef4ff2a 100644 --- a/.github/workflows/pull-request-gradle-build-test.yml +++ b/.github/workflows/pull-request-gradle-build-test.yml @@ -57,7 +57,7 @@ jobs: - name: Error Report Files를 Artifacts에 업로드 if: ${{ failure() }} - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: error_report_files path: error_report_files_*.tar.gz From 7c67ba1ed9a52beb84031ef3ac181f8f75a62fd3 Mon Sep 17 00:00:00 2001 From: binary-ho Date: Sun, 26 Jan 2025 17:14:44 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor:=20cd=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=EB=A5=BC=20=EC=9C=84=ED=95=B4,=20=ED=8A=B8=EB=A6=AC?= =?UTF-8?q?=EA=B1=B0=20=ED=83=80=EA=B2=9F=EC=97=90=20PR=20synchronize=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fdc6cff..bd787aa 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,6 +3,8 @@ name: Deploy! on: push: branches: [ "main" ] + pull_request: + types: [ synchronize ] jobs: deploy: From bd5679351f14114381a75fa1160c3edbaafe6f11 Mon Sep 17 00:00:00 2001 From: binary-ho Date: Sun, 26 Jan 2025 17:23:43 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor:=20netcat=20->=20netcat-openbsd?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index bd787aa..dd9ba6b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -48,7 +48,7 @@ jobs: - name: Deploy! run: | sudo apt-get update - sudo apt-get install -y curl netcat openssh-client + sudo apt-get install -y curl netcat-openbsd openssh-client curl -L "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64" \ -o /usr/local/bin/cloudflared chmod +x /usr/local/bin/cloudflared From abc604206c4ef4ac31d96e681ee920b37d119d64 Mon Sep 17 00:00:00 2001 From: binary-ho Date: Sun, 26 Jan 2025 17:28:11 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=EC=B6=94=EA=B0=80=ED=95=9C=20?= =?UTF-8?q?PR=20=ED=8A=B8=EB=A6=AC=EA=B1=B0=20=ED=83=80=EA=B2=9F=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dd9ba6b..bf9faf5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,8 +3,6 @@ name: Deploy! on: push: branches: [ "main" ] - pull_request: - types: [ synchronize ] jobs: deploy: