Skip to content

Commit

Permalink
deployment: optimized build process & fix action status (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamSlightlyWind authored Oct 10, 2024
1 parent 602e8e2 commit ce99217
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 124 deletions.
95 changes: 35 additions & 60 deletions .github/workflows/start-server.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Start Server
name: Deploy Server

concurrency:
group: ${{ github.workflow }}
Expand All @@ -7,40 +7,50 @@ concurrency:
on:
workflow_dispatch:
#push:
#pull_request:

jobs:
start-server:
runs-on: ubuntu-latest

steps:
- name: Install dependencies
run: |
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \
&& echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
| sudo tee /etc/apt/sources.list.d/ngrok.list
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
sudo apt update
sudo apt install ngrok cloudflare-warp fish
ngrok config add-authtoken ${{ secrets.NGROK_AUTHTOKEN }}
warp-cli --accept-tos connect
- name: Checkout repository
uses: actions/checkout@v2

#- name: Run ngrok SSH
# id: ngrok
# uses: tmshkr/ngrok-ssh@latest
# with:
# SSH_CLIENT_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
# NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
- name: Pull MSSQL container
run: |
docker run --network host -p 1433:1433 -d --name mssql \
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" \
mcr.microsoft.com/mssql/server:latest
sleep 10
docker exec mssql /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -C -Q "ALTER LOGIN [sa] WITH PASSWORD= '${{ secrets.SQLPASSWORD }}', CHECK_POLICY = OFF"
- name: Setup MSSQL database
run: |
docker cp server/mssql/. mssql:/tmp
docker exec mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i /tmp/reset.sql
docker exec mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i /tmp/table.sql
docker exec mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i /tmp/procedure.sql
docker exec mssql /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i /tmp/insert.sql
- name: Build Tomcat Docker Image
run: |
mv server/tomcat server/docker/tomcat
docker build -t tomcat:majors_choice server/docker/tomcat
- name: Run Tomcat Docker Container
run: |
docker run --network host -p 8080:8080 -d --name tomcat \
-e "PAYMENT_CODE=${{ secrets.PAYMENT_CODE }}" \
-e "PAYMENT_SECRET=${{ secrets.PAYMENT_SECRET }}" \
-e "SQLPASSWORD=${{ secrets.SQLPASSWORD }}" \
-e "EMAIL_ADDRESS=${{ secrets.EMAIL_ADDRESS }}" \
-e "EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }}" \
-e "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" \
tomcat:majors_choice
- name: Reverse proxy
run: |
#Cloudflare
################
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
cd server/cloudflare
Expand All @@ -51,41 +61,6 @@ jobs:
sudo cp * /etc/cloudflared/
sudo cloudflared service install
sudo service cloudflared start
- name: Set up Docker Build
uses: docker/setup-buildx-action@v1

- name: Set up Docker
run: |
docker pull mcr.microsoft.com/mssql/server
docker pull tomcat:latest
- name: Run MSSQL container
run: |
docker run --network host -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:latest
sleep 10
sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q "ALTER LOGIN [sa] WITH PASSWORD= '${{ secrets.SQLPASSWORD }}', CHECK_POLICY = OFF"
- name: Run Tomcat container
run: |
docker run --network host -d --name tomcat -p 8080:8080 -e "PAYMENT_CODE=${{ secrets.PAYMENT_CODE }}" -e "PAYMENT_SECRET=${{ secrets.PAYMENT_SECRET }}" -e "SQLPASSWORD=${{ secrets.SQLPASSWORD }}" -e "EMAIL_ADDRESS=${{ secrets.EMAIL_ADDRESS }}" -e "EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }}" -e "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" tomcat:latest
mv ./server/tomcat/dist/*.war ./server/tomcat/dist/ROOT.war
docker cp ./server/tomcat/dist/ROOT.war `docker ps -q --filter ancestor=tomcat`:/usr/local/tomcat/webapps/
docker restart `docker ps -q --filter ancestor=tomcat`
env:
SQLPASSWORD: ${{ secrets.SQLPASSWORD }}

- name: Create database
run: |
echo "creating database"
sqlcmd -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/reset.sql
echo "creating tables"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/table.sql
echo "creating procedures"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/procedure.sql
echo "inserting data"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/insert.sql
- name: Show tomcat Logs
timeout-minutes: 60
run: docker logs -f `docker ps -q --filter ancestor=tomcat`
run: timeout 60m docker logs -f tomcat || true
91 changes: 91 additions & 0 deletions .github/workflows/start-server.yml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Start Server

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

on:
workflow_dispatch:
#push:
#pull_request:

jobs:
start-server:
runs-on: ubuntu-latest

steps:
- name: Install dependencies
run: |
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null \
&& echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
| sudo tee /etc/apt/sources.list.d/ngrok.list
curl -fsSL https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
sudo apt update
sudo apt install ngrok cloudflare-warp fish
ngrok config add-authtoken ${{ secrets.NGROK_AUTHTOKEN }}
warp-cli --accept-tos connect

- name: Checkout repository
uses: actions/checkout@v2

#- name: Run ngrok SSH
# id: ngrok
# uses: tmshkr/ngrok-ssh@latest
# with:
# SSH_CLIENT_PUBLIC_KEY: ${{ secrets.SSH_PUBLIC_KEY }}
# NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}

- name: Reverse proxy
run: |
#Cloudflare
################
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
cd server/cloudflare
unzip -P "${{ secrets.CLOUDFLARE_ZIP_PASSWORD }}" .cloudflared.zip
mv .cloudflared ~/
cd ~/.cloudflared
sudo mkdir -p /etc/cloudflared
sudo cp * /etc/cloudflared/
sudo cloudflared service install
sudo service cloudflared start

- name: Set up Docker Build
uses: docker/setup-buildx-action@v1

- name: Set up Docker
run: |
docker pull mcr.microsoft.com/mssql/server
docker pull tomcat:latest

- name: Run MSSQL container
run: |
docker run --network host -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=YourStrong@Passw0rd" -p 1433:1433 -d mcr.microsoft.com/mssql/server:latest
sleep 10
sqlcmd -S localhost -U sa -P 'YourStrong@Passw0rd' -Q "ALTER LOGIN [sa] WITH PASSWORD= '${{ secrets.SQLPASSWORD }}', CHECK_POLICY = OFF"

- name: Run Tomcat container
run: |
docker run --network host -d --name tomcat -p 8080:8080 -e "PAYMENT_CODE=${{ secrets.PAYMENT_CODE }}" -e "PAYMENT_SECRET=${{ secrets.PAYMENT_SECRET }}" -e "SQLPASSWORD=${{ secrets.SQLPASSWORD }}" -e "EMAIL_ADDRESS=${{ secrets.EMAIL_ADDRESS }}" -e "EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }}" -e "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" tomcat:latest
mv ./server/tomcat/dist/*.war ./server/tomcat/dist/ROOT.war
docker cp ./server/tomcat/dist/ROOT.war `docker ps -q --filter ancestor=tomcat`:/usr/local/tomcat/webapps/
docker restart `docker ps -q --filter ancestor=tomcat`
env:
SQLPASSWORD: ${{ secrets.SQLPASSWORD }}

- name: Create database
run: |
echo "creating database"
sqlcmd -S localhost -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/reset.sql
echo "creating tables"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/table.sql
echo "creating procedures"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/procedure.sql
echo "inserting data"
sqlcmd -S localhost -d major -U sa -P ${{ secrets.SQLPASSWORD }} -i ./server/mssql/insert.sql

- name: Show tomcat Logs
timeout-minutes: 60
run: docker logs -f `docker ps -q --filter ancestor=tomcat`
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ A project focused on DevOps automation and auto-deployment of a professional e-c

## Trigger GitHub Action

[![Deploy Server](https://img.shields.io/badge/Deploy%20Server-blue)](https://themajorones-deploy-choice.vercel.app/api/trigger)
<a href="https://themajorones-deploy-choice.vercel.app/api/trigger">
<img src="https://github.com/iamSlightlyWind/majors_choice/actions/workflows/start-server.yml/badge.svg" alt="Build Status" />
</a>

Everyone can test the website at https://choice.themajorones.dev by pressing the "Deploy Server" button.
> [!NOTE]
> The server takes up to 3 minutes to deploy, and will not start again unless the previous run has expired (1 hour, configurable in workflow).
Anyone can test the website at https://choice.themajorones.dev by pressing the "Deploy Server" button.

> [!NOTE]
> The server should boots in 1 minute once triggered, and will not start again unless the previous run has expired (1 hour, configurable in workflow).
## Project Overview

Expand Down
44 changes: 0 additions & 44 deletions package-lock.json

This file was deleted.

16 changes: 0 additions & 16 deletions package.json

This file was deleted.

10 changes: 10 additions & 0 deletions server/docker/tomcat/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM tomcat:10.0

RUN apt-get update && apt-get install -y ant

WORKDIR /root
COPY tomcat tomcat
WORKDIR /root/tomcat

RUN ant -Dj2ee.server.home=/usr/local/tomcat/ -Dlibs.CopyLibs.classpath=copylibs
RUN mv dist/*.war /usr/local/tomcat/webapps/ROOT.war

0 comments on commit ce99217

Please sign in to comment.