-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from COS301-SE-2024/feat/documentation/contain…
…erizing-docs chore: Update deploy docs logic to deploy to vm
- Loading branch information
Showing
5 changed files
with
100 additions
and
57 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,4 +1,4 @@ | ||
name: Deploy Docs site to Pages | ||
name: Deploy Docs site to Live site | ||
|
||
on: | ||
push: | ||
|
@@ -21,7 +21,7 @@ defaults: | |
|
||
jobs: | ||
# Build job | ||
build: | ||
build-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
|
@@ -32,43 +32,70 @@ jobs: | |
with: | ||
bun-version: latest # or "latest", "canary", <sha> | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v4 | ||
with: | ||
# Automatically inject basePath in your Next.js configuration file and disable | ||
# server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized). | ||
# | ||
# You may remove this line if you want to manage the configuration yourself. | ||
static_site_generator: next | ||
|
||
- name: Install dependencies with Bun | ||
run: bun install | ||
|
||
- name: Build with Next.js | ||
run: bun run build | ||
run: bun run build | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: documentation/occupi-docs/out | ||
build-push-docker: | ||
name: Build and Push Documentation Docker Image | ||
runs-on: ubuntu-latest | ||
needs: build-test | ||
|
||
# Deployment job | ||
deploy: | ||
name: Deploy to GitHub Pages | ||
needs: build | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment | ||
permissions: | ||
pages: write # to deploy to Pages | ||
id-token: write # to verify the deployment originates from an appropriate source | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
# Deploy to the github-pages environment | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: documentation/occupi-docs | ||
file: documentation/occupi-docs/Dockerfile | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: ${{ secrets.DOCKER_USERNAME }}/occupi-documentation:latest | ||
|
||
deploy: | ||
name: Deploy Documentation | ||
runs-on: ubuntu-latest | ||
needs: build-push-docker | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Copy files to VM | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.VM_IP }} | ||
username: ${{ secrets.VM_USERNAME }} | ||
key: ${{ secrets.VM_SSH_KEY }} | ||
source: "documentation/occupi-docs/docker-compose.yml,documentation/occupi-docs/Dockerfile" | ||
target: "/home/${{ secrets.VM_USERNAME }}/occupi-docs" | ||
|
||
# SSH to VM and run commands | ||
- name: SSH to VM | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.VM_IP }} | ||
username: ${{ secrets.VM_USERNAME }} | ||
key: ${{ secrets.VM_SSH_KEY }} | ||
script: | | ||
cd /home/${{ secrets.VM_USERNAME }}/occupi-docs/documentation/occupi-docs | ||
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | ||
DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} docker compose -f docker-compose.yml down | ||
DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} docker compose -f docker-compose.yml pull | ||
DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }} docker compose -f docker-compose.yml up -d |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Use the official bun image as a base | ||
FROM oven/bun:latest | ||
|
||
# Set the current working directory inside the container | ||
WORKDIR /app | ||
|
||
# copy bun.lockb package.json | ||
COPY bun.lockb package.json ./ | ||
|
||
# install dependencies | ||
RUN bun install | ||
|
||
# copy the source code into the container | ||
COPY . . | ||
|
||
# Build the next.js application | ||
RUN bun run build | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 3001 | ||
|
||
# Command to run the executable | ||
CMD ["bun", "start"] |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
services: | ||
occupi-documentation: | ||
image: $DOCKER_USERNAME/occupi-documentation:latest | ||
container_name: occupi-documentation | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "3001:3000" | ||
networks: | ||
- webnet | ||
|
||
networks: | ||
webnet: | ||
external: true |
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
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