From bb0d2910d6413c544a21d9a22182d2e83113e098 Mon Sep 17 00:00:00 2001 From: WasinUddy Date: Mon, 11 Nov 2024 20:00:25 +0700 Subject: [PATCH] feat(CICD): Automatic build of Montainer image --- .../build-montainer-preview-image.yaml | 65 +++++++++++++++++++ .../build-montainer-stable-image.yaml | 63 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 .github/workflows/build-montainer-preview-image.yaml create mode 100644 .github/workflows/build-montainer-stable-image.yaml diff --git a/.github/workflows/build-montainer-preview-image.yaml b/.github/workflows/build-montainer-preview-image.yaml new file mode 100644 index 0000000..9090c9a --- /dev/null +++ b/.github/workflows/build-montainer-preview-image.yaml @@ -0,0 +1,65 @@ +name: Build Montainer (Preview) Image + +on: + push: + paths: + - 'Dockerfile' + - 'versions/preview.txt' + - '.github/workflows/build-montainer-preview-image.yaml' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: true # Stop all jobs if one fails + + steps: + + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: 3.11 + + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Download and Extract Minecraft Server + run: | + python3 -m pip install --upgrade pip + python3 -m pip install requests==2.31.0 + python3 scripts/download_minecraft_server.py --type=preview + + - name: Build frontend web static + run: | + cd frontend + npm install + npm run build + + - name: Fetch Versions + run: | + echo "PREVIEW_VERSION=$(cat versions/preview.txt)" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - name: Build Montainer (preview) Image + run: | + docker build . --tag ghcr.io/wasinuddy/montainer-preview:latest --tag ghcr.io/wasinuddy/montainer-preview:${{ env.PREVIEW_VERSION }} + docker push ghcr.io/wasinuddy/montainer-preview:latest + docker push ghcr.io/wasinuddy/montainer-preview:${{ env.PREVIEW_VERSION }} + diff --git a/.github/workflows/build-montainer-stable-image.yaml b/.github/workflows/build-montainer-stable-image.yaml new file mode 100644 index 0000000..0e40549 --- /dev/null +++ b/.github/workflows/build-montainer-stable-image.yaml @@ -0,0 +1,63 @@ +name: Build Montainer (Stable) Image + +on: + push: + paths: + - 'Dockerfile' + - 'versions/stable.txt' + - '.github/workflows/build-montainer-stable-image.yaml' + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: true # Stop all jobs if one fails + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Set up Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: 20.x + + - name: Download and Extract Minecraft Server + run: | + python3 -m pip install --upgrade pip + python3 -m pip install requests==2.31.0 + python3 scripts/download_minecraft_server.py --type=stable + + - name: Build frontend web static + run: | + cd frontend + npm install + npm run build + + - name: Fetch Versions + run: | + echo "STABLE_VERSION=$(cat versions/stable.txt)" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + + - name: Build Montainer (Stable) Image + run: | + docker build . --tag ghcr.io/wasinuddy/montainer-stable:latest --tag ghcr.io/wasinuddy/montainer-stable:${{ env.STABLE_VERSION }} + docker push ghcr.io/wasinuddy/montainer-stable:latest + docker push ghcr.io/wasinuddy/montainer-stable:${{ env.STABLE_VERSION }} +