Skip to content

Commit

Permalink
feat: addional framework support and image update (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaitanyarai899 authored Sep 16, 2024
1 parent 2b9fb7a commit 13b0f9b
Show file tree
Hide file tree
Showing 12 changed files with 1,028 additions and 239 deletions.
33 changes: 24 additions & 9 deletions automatic-deployment-CICD-template/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu
FROM ubuntu as javascript-automation

# nvm requirements
RUN apt-get update
Expand All @@ -8,19 +8,34 @@ RUN mkdir -p /usr/local/nvm
ENV NVM_DIR /usr/local/nvm

# IMPORTANT: set the exact version
ENV NODE_VERSION v21.7.3
ENV DEFAULT_NODE_VERSION v20.10.0
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $DEFAULT_NODE_VERSION && nvm use --delete-prefix $DEFAULT_NODE_VERSION"

# add node and npm to the PATH
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
ENV NODE_PATH $NVM_DIR/versions/node/$DEFAULT_NODE_VERSION/bin
ENV PATH $NODE_PATH:$PATH

RUN npm install -g serve astro
RUN npm install -g serve astro http-server yarn pnpm

RUN apt install inotify-tools -y
# RUN apt-get update && \
# apt-get install -y --no-install-recommends \
# python3 \
# python3-pip \
# python3.12-venv

WORKDIR /app
COPY javascript/*.sh common/*.sh index.html /app/
RUN chmod +x *.sh

#CMD /bin/bash -c "/app/js.sh | logdy --ui-ip 0.0.0.0"
CMD ["/app/main.sh"]

FROM python:3.9-alpine3.19 as python-automation

RUN apk add git bash
WORKDIR /app
COPY script.sh /app
RUN chmod +x script.sh
COPY python/*.sh common/*.sh index.html /app/
RUN chmod +x *.sh

CMD ["/bin/bash", "/app/script.sh"]
CMD ["bash", "/app/main.sh"]
36 changes: 30 additions & 6 deletions automatic-deployment-CICD-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,35 @@ Note: This tool is currently in the MVP phase.
Deploying applications can often involve a steep learning curve, particularly when dealing with containerization and CI/CD pipelines. Our tool simplifies this by automating deployments directly from your GitHub repository to the Akash Network. It supports several popular JavaScript frameworks, making it a versatile option for many developers.

### Supported Frameworks Include:
- React
- React + Vite
- Astro.js
- Vue.js
- Simple HTML,CSS and JS application

#### JavaScript Frameworks:

- **React**
- **Vite-react**
- **Vue.js**
- **Astro**
- **Angular**
- **Express.js**
- **Next.js**
- **Ember.js**
- **Gatsby.js**
- **Vite**
- **VitePress**
- **Nuxt.js**
- **Preact**
- **Ionic React**
- **Ionic Angular**
- **Stencil**
- **Gridsome**
- **Umi.js**
- **11ty.js**
- **Remix**
- **VuePress**

#### Python Frameworks:

- **Django**
- **Flask**

## Key Features That Set Our Tool Apart

Expand Down Expand Up @@ -50,7 +74,7 @@ For a practical application, here’s how you might set up your SDL file:
version: "2.0"
services:
service-1:
image: hoomanhq/automation:0.201
image: hoomanhq/automation:0.421
expose:
- port: 3000
as: 80
Expand Down
121 changes: 121 additions & 0 deletions automatic-deployment-CICD-template/common/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/bash

# Function to update the repository
update_repo() {
# Get the latest commit hash from the remote repository
remote_hash=$(git ls-remote --heads origin $BRANCH_NAME | awk '{print $1}')

# Compare bad commit hash with remote hash
for hash in "${bad_commit_hashes[@]}"; do
echo "bad hash: $hash"
echo "remote hash: $remote_hash"
if [ "$remote_hash" = "$hash" ]; then
echo "[*] Bad commit detected on remote repository. Pull aborted..."
return 1
fi
done

# Get the latest commit hash from the local repository
local_hash=$(git rev-parse $BRANCH_NAME)

if [ "$remote_hash" != "$local_hash" ]; then
echo "[*] Changes detected, pulling latest changes.."
git pull
return 0
else
return 1
fi
}

previous_commit() {
bad_commit_hashes=()
current_commit=$(git rev-parse HEAD)
bad_commit_hashes+=("$current_commit")

if ! git checkout $BRANCH_NAME; then
echo "[*] Error: Failed to checkout the branch $BRANCH_NAME"
echo "[*] Error: Failed to get the previous commit hash"
return 1
fi

if ! git reset --hard $previous_hash; then
echo "[*] Error: Failed to reset to the previous commit $previous_hash"
return 1
fi

current_hash=$(git rev-parse HEAD)

if [ "$current_hash" != "$previous_hash" ]; then
echo "[*] Error: The reset to the previous commit $previous_hash failed"
return 1
fi

echo "[*] Successfully rolled back to the previous commit $previous_hash"
return 0
}

# Function to clone the repository
clone_repo() {
if [ ! -d "$REPO_DIR" ]; then
echo "[*] Cloning the repository..."

if [ -n "$GITHUB_ACCESS_TOKEN" ]; then
echo "[*] Github access token specified. Cloning the private repository..."
REPO_URL=$(echo "$REPO_URL" | sed "s|https://github.com/|https://${GITHUB_ACCESS_TOKEN}@github.com/|g")
fi

if [ -n "$GITLAB_ACCESS_TOKEN" ]; then
echo "[*] Gitlab access token specified. Cloning the private repository..."
REPO_URL=$(echo "$REPO_URL" | sed "s|https://gitlab.com|https://auth:${GITLAB_ACCESS_TOKEN}@gitlab.com|g")
fi

if [ -n "$BITBUCKET_ACCESS_TOKEN" ]; then
echo "[*] Bitbucket access token specified. Cloning the private repository..."
REPO_URL=$(echo "$REPO_URL" | sed "s|https://bitbucket.org|https://${BITBUCKET_USER}:${BITBUCKET_ACCESS_TOKEN}@bitbucket.org|g")
fi

if ! git clone "$REPO_URL" "$REPO_DIR"; then
echo "[*] Error: Failed to clone the repository"
exit 1
fi
cd "$REPO_DIR"

# Change directory to the frontend folder if specified
if [ -n "$FRONTEND_FOLDER" ]; then
if [ ! -d "$FRONTEND_FOLDER" ]; then
echo "[*] Error: Frontend folder '$FRONTEND_FOLDER' not found"
exit 1
fi
cd "$FRONTEND_FOLDER"
echo "[*] Changed directory to $FRONTEND_FOLDER"
fi

else
echo "[*] Repository already exists on server, pulling latest changes..."
cd "$REPO_DIR"
if ! git pull; then
echo "[*] Error: Failed to pull the latest changes"
exit 1
fi
fi
}

rollback_commit() {
if [ -n "$COMMIT_HASH" ]; then
if git checkout "$COMMIT_HASH" >/dev/null 2>&1; then
echo "[*] Successfully rolled back to $COMMIT_HASH"
else
echo "[*] Error: Failed to checkout commit $COMMIT_HASH"
return 1
fi
fi
}

initial_serve() {
if ! command -v http-server &> /dev/null; then
nohup python3 -m http.server 3000 --bind 0.0.0.0 > /dev/null 2>&1 &
else
nohup http-server -p 3000 -f index.html > /dev/null 2>&1 &
fi
SERVE_PID=$!
}
2 changes: 1 addition & 1 deletion automatic-deployment-CICD-template/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: "2.0"
services:
service-1:
image: hoomanhq/automation:0.201
image: hoomanhq/automation:0.421
expose:
- port: 3000
as: 80
Expand Down
11 changes: 11 additions & 0 deletions automatic-deployment-CICD-template/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div style="width: 100%; height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column; margin-top: -10vh;">
<span style="font-family: Arial, sans-serif; font-size: 18px; color: #333; font-weight: bold;">We are building your application.</span>
<br>
<span style="font-family: Arial, sans-serif; font-size: 18px; color: #666;">This page will refresh once it's done.</span>
</div>

<script>
setInterval(() => {
location.reload();
}, 10000);
</script>
Loading

0 comments on commit 13b0f9b

Please sign in to comment.