Skip to content

Commit

Permalink
Merge pull request #18 from OpenIPC/master
Browse files Browse the repository at this point in the history
New packaging and release
  • Loading branch information
mikecarr authored Nov 12, 2024
2 parents 65fc8e8 + 30ec45e commit f964088
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 414 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Package and Release

on:
push:
branches:
- stable
workflow_dispatch:

jobs:
build-and-release:
runs-on: ubuntu-latest

env:
APP_NAME: "improver"
VERSION: ${{ github.run_id }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Package source code
run: |
ARCHIVE_NAME="${APP_NAME}_source_${VERSION}.tar.gz"
echo "Packaging source code into ${ARCHIVE_NAME}..."
tar czvf $ARCHIVE_NAME \
app/ \
requirements.txt \
gunicorn_config.py \
run.sh \
update_nginx.sh \
improver.service \
config/
- name: List packaged files
run: ls -lh *.tar.gz

- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "release-${VERSION}"
release_name: "Improver Release ${VERSION}"
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: "${APP_NAME}_source_${VERSION}.tar.gz"
asset_name: "${APP_NAME}_source_${VERSION}.tar.gz"
asset_content_type: application/gzip
51 changes: 0 additions & 51 deletions .github/workflows/release.yml

This file was deleted.

Empty file removed MANIFEST.in
Empty file.
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Define variables for image and container names
IMAGE_NAME := py-config-gs
CONTAINER_NAME := py-config-gs
DOCKER_COMPOSE_FILE := docker-compose.yaml
PORT := 8080 # The port on the host to access Nginx

# Target to build the Docker image using Docker Compose
build:
@echo "Building Docker images with Docker Compose..."
docker-compose -f $(DOCKER_COMPOSE_FILE) build

# Target to run the Docker containers in the foreground
run: build
@echo "Starting Docker containers..."
docker-compose -f $(DOCKER_COMPOSE_FILE) up

# Target to run Docker containers in detached mode (background)
run-detached: build
@echo "Starting Docker containers in detached mode..."
docker-compose -f $(DOCKER_COMPOSE_FILE) up -d

# Target to stop the Docker containers
stop:
@echo "Stopping Docker containers..."
docker-compose -f $(DOCKER_COMPOSE_FILE) down

# Target to view logs from all services
logs:
@echo "Showing logs from all Docker services..."
docker-compose -f $(DOCKER_COMPOSE_FILE) logs -f

# Target to clean up all images and containers
clean:
@echo "Removing Docker images and containers..."
docker-compose -f $(DOCKER_COMPOSE_FILE) down --rmi all --volumes --remove-orphans

# Help target to show available commands
help:
@echo "Available commands:"
@echo " make build - Build the Docker images with Docker Compose"
@echo " make run - Run the Docker containers in the foreground"
@echo " make run-detached - Run the Docker containers in detached mode"
@echo " make stop - Stop the running Docker containers"
@echo " make logs - View logs for all services"
@echo " make clean - Remove all containers, images, and volumes"
@echo " make help - Show this help message"
17 changes: 9 additions & 8 deletions deploy_improver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ echo "Creating necessary directories..."
sudo mkdir -p "$DEST_DIR"
sudo mkdir -p "$SCRIPTS_DIR"
sudo mkdir -p "$LOG_DIR"
sudo chown -R www-data:www-data "$LOG_DIR"
sudo chmod -R 755 "$LOG_DIR"

# Step 2: Install required packages
echo "Installing gunicorn..."
Expand Down Expand Up @@ -70,11 +68,7 @@ sed -i "/^}/i \\
add_header Cache-Control \"public, max-age=2592000\";\\
}\\
\\n\\
# Custom error page for server errors\\
error_page 500 502 503 504 /50x.html;\\
location = /50x.html {\\
root /usr/share/nginx/html;\\
}" "$NGINX_CONFIG"
" "$NGINX_CONFIG"

# Test Nginx configuration
echo "Testing Nginx configuration..."
Expand All @@ -91,19 +85,26 @@ else
fi

# Step 5: Add sudo permissions for www-data user
echo "Adding sudo permissions for www-data..."
if ! sudo grep -q "www-data.*systemctl" "$SUDOERS_FILE"; then
echo "Adding sudo permissions for www-data..."
echo "www-data ALL=(ALL) NOPASSWD: /bin/systemctl restart /etc/systemd/system/wifibroadcast.service.wants/[email protected] /bin/systemctl restart openipc, /bin/systemctl stop openipc, /bin/systemctl start openipc" | sudo tee -a "$SUDOERS_FILE"
echo "www-data ALL=(ALL) NOPASSWD: /bin/systemctl restart wifibroadcast.service, /bin/systemctl restart openipc, /bin/systemctl stop openipc, /bin/systemctl start openipc" | sudo tee -a "$SUDOERS_FILE"
else
echo "www-data already has necessary sudo permissions."
fi

# Step 6: Verify the deployment
echo "Verifying the deployment..."
if [ -f "$DEST_DIR/run.sh" ]; then
echo "Run script found. You can start the application with:"
echo "sudo $DEST_DIR/run.sh"
else
echo "Run script not found. Please check the extracted files."
fi

echo "chnging perms on $LOG_DIR"
sudo chown -R www-data:www-data "$LOG_DIR"
sudo chmod -R 755 "$LOG_DIR"


echo "Deployment completed successfully."
4 changes: 2 additions & 2 deletions package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ tar czvf $ARCHIVE_NAME \
run.sh \
update_nginx.sh \
improver.service \
py-config-gs.json
config/


# Step 2: Display the packaged file
echo "Packaged application into: $ARCHIVE_NAME"

# Step 3: Instructions for deployment
echo "To deploy on Radxa, transfer $ARCHIVE_NAME and update_nginx.sh using SCP:"
echo "scp $ARCHIVE_NAME update_nginx.sh deploy_improver.sh root@radxa:/tmp/"
echo "scp $ARCHIVE_NAME deploy_improver.sh root@radxa:/tmp/"
16 changes: 0 additions & 16 deletions py_config_gs/_version.py

This file was deleted.

Loading

0 comments on commit f964088

Please sign in to comment.