Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy to Dawn Staging Theme [Aligent's Shopify Test Store] #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
THEME_PATH=theme
IMAGE_NAME=naturally-sweet-shopify
CONTAINER_NAME=naturally-sweet-shopify_cli-container
SHOPIFY_STORE=coffeeequalslife.myshopify.com
THEME_PRODUCTION_ID=157104111920
THEME_STAGING_ID=170306994480
FAIL_LEVEL=crash
147 changes: 147 additions & 0 deletions .github/workflows/shopify-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Naturally Sweet Shopify Theme Deployment

on:
push:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My GHA might be dated, but I found this too sensitive in the past.

I have previously used the pull_request trigger instead and in the Job added a merge check to only run the job when the merge completed.

on:
  pull_request:
    types:
      - closed
    branches:
      - staging

jobs:
  theme-check:
    name: Theme Check
    # PR must must be merged, not closed to trigger a deployment
    if: github.event.pull_request.merged
   ...

branches:
- 'feature/*' # Trigger for feature branches for theme checks
- staging # Trigger for the staging branch to push as unpublished
- main # Trigger for the main branch to publish the theme

jobs:
theme-check:
runs-on: ubuntu-latest
if: github.ref_name == 'main' || github.ref_name == 'staging' || startsWith(github.ref_name, 'feature/')
container:
image: aaronmedinaaligent/shopify-cli-base:latest
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_SECRET_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most GHA default actions are @v4 now ... otherwise you'll get pipeline warnings about deprecated Node


- name: Verify Ruby Installation
run: ruby -v

- name: Verify Node.js Installation
run: |
node -v
npm -v

- name: Verify Shopify CLI Installation
run: shopify version

- name: List files in current directory
run: |
echo "Current directory: $(pwd)"
ls -al

- name: Read variables from file
run: |
# Check if the file exists
if [ ! -f .env ]; then
echo "Error: .env file not found!"
exit 1
fi

# Read each line from .env, ignoring comments and empty lines, and add to GitHub environment
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and lines that start with #
[[ -z "$line" || "$line" =~ ^# ]] && continue

# Print each line being processed for debugging
echo "Processing line: $line"

# Add to GitHub environment
echo "$line" >> $GITHUB_ENV
done < .env

- name: Check /theme Directory Exists
run: |
if [ ! -d "./theme" ]; then
echo "/theme directory does not exist."
exit 1
fi
echo "/theme directory exists."

- name: List Files in /theme
run: find theme -exec ls -ld --time-style=long-iso {} \; | awk '{print $6, $7, $8, $9}'

- name: Run Shopify Theme Check
run: shopify theme check --fail-level=$FAIL_LEVEL --path=$THEME_PATH

deploy:
runs-on: ubuntu-latest
needs: theme-check # Ensure deploy only runs if theme-check is successful
if: github.ref_name == 'main' || github.ref_name == 'staging'
container:
image: aaronmedinaaligent/shopify-cli-base:latest
credentials:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_SECRET_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Verify Ruby Installation
run: ruby -v

- name: Verify Node.js Installation
run: |
node -v
npm -v

- name: Verify Shopify CLI Installation
run: shopify version

- name: List files in current directory
run: |
echo "Current directory: $(pwd)"
ls -al

- name: Read variables from file
run: |
# Check if the file exists
if [ ! -f .env ]; then
echo "Error: .env file not found!"
exit 1
fi

# Read each line from .env, ignoring comments and empty lines, and add to GitHub environment
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines and lines that start with #
[[ -z "$line" || "$line" =~ ^# ]] && continue

# Print each line being processed for debugging
echo "Processing line: $line"

# Add to GitHub environment
echo "$line" >> $GITHUB_ENV
done < .env

- name: Check /theme Directory Exists
run: |
if [ ! -d "./theme" ]; then
echo "/theme directory does not exist."
exit 1
fi
echo "/theme directory exists."

- name: List Files in /theme
run: find theme -exec ls -ld --time-style=long-iso {} \; | awk '{print $6, $7, $8, $9}'

- name: Deploy Theme
shell: bash
run: |
if [[ "${GITHUB_REF_NAME}" == "staging" ]]; then
echo -e "Deploying to \033[36mSTAGING\033[0m..."
shopify theme push --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --theme="$THEME_STAGING_ID" --path=$THEME_PATH --verbose --nodelete
elif [[ "${GITHUB_REF_NAME}" == "main" ]]; then
echo -e "Deploying to \033[36mPRODUCTION\033[0m..."
shopify theme push --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --theme="$THEME_PRODUCTION_ID" --path=$THEME_PATH --verbose --allow-live
fi

env:
SHOPIFY_ACCESS_TOKEN: ${{ secrets.SHOPIFY_ACCESS_TOKEN }}


2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# prevent .access_token from being committed
.access_token
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use the custom base image with Ruby, Node.js, npm, and Shopify CLI pre-installed
FROM aaronmedinaaligent/shopify-cli-base:latest

# Set build arguments for user ID and group ID
ARG USER_ID
ARG GROUP_ID

# Create a group and user matching the host UID and GID to avoid permission issues
RUN groupadd -g $GROUP_ID shopifygroup && \
useradd -u $USER_ID -g shopifygroup -m shopifyuser

# Create the /theme directory and set the correct permissions
RUN mkdir -p /theme && chown shopifyuser:shopifygroup /theme

# Install xdg-utils for opening URLs
RUN apt-get update && apt-get install -y xdg-utils

# Modify permissions during the build process
RUN chown -R shopifyuser:shopifygroup /usr/local/lib/node_modules/@shopify/cli/dist/assets/cli-ruby

# Set the working directory
WORKDIR /theme

# Switch to the non-root user for security
USER shopifyuser

# Verify installations
RUN node -v && npm -v && ruby -v && bundler -v && shopify version && xdg-open --version

# Default command to keep the container running in an interactive shell
CMD ["bash"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
25 changes: 25 additions & 0 deletions scripts/shopify-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if IMAGE_NAME variable is set
check_variable "IMAGE_NAME"

# Build the Docker image with the current user's UID and GID
echo -e "Building Docker image '$IMAGE_NAME' with USER_ID=$(id -u) and GROUP_ID=$(id -g)..."
docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) --progress=plain -t "$IMAGE_NAME" .

# Check if the build was successful
if [ $? -eq 0 ]; then
echo -e "Docker image '$IMAGE_NAME' built successfully."
else
echo -e "Failed to build Docker image '$IMAGE_NAME'."
exit 1
fi
17 changes: 17 additions & 0 deletions scripts/shopify-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set
check_variable "SHOPIFY_STORE"
check_variable "CONTAINER_NAME"

# Run the Shopify theme development command inside the container
docker exec -it "$CONTAINER_NAME" shopify theme dev --store="$SHOPIFY_STORE" --password="$SHOPIFY_ACCESS_TOKEN" --nodelete
18 changes: 18 additions & 0 deletions scripts/shopify-get-theme-info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/shopify-utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if required variables are set
check_variable "SHOPIFY_STORE"
check_variable "SHOPIFY_ACCESS_TOKEN"

# Fetch detailed theme information using the Shopify Admin API
curl -s -X GET "https://$SHOPIFY_STORE/admin/api/2023-07/themes.json" \
-H "X-Shopify-Access-Token: $SHOPIFY_ACCESS_TOKEN" | jq .
42 changes: 42 additions & 0 deletions scripts/shopify-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set
check_variable "SHOPIFY_STORE"
check_variable "CONTAINER_NAME"

# Check if the container is already running
if is_container_running "$CONTAINER_NAME"; then
echo -e "\n\nContainer ${YELLOW}$CONTAINER_NAME${RESET} is already running."
else
# Check if the container exists but is stopped
if docker ps -aq -f name="$CONTAINER_NAME" | grep -q .; then
start_existing_container "$CONTAINER_NAME"
else
run_new_container "$CONTAINER_NAME"

# Check if the container started successfully
if [ $? -eq 0 ]; then
echo -e "\n\nContainer ${YELLOW}'$CONTAINER_NAME'${RESET} is running in detached mode."
else
echo -e "\n\n${RED}FAILED${RESET} to start the container."
exit 1
fi
fi
fi

echo -e "\nUse the following command to execute commands inside the container:"
echo -e "\n${GREEN}docker exec -it $CONTAINER_NAME <command>${RESET}"
echo -e "\n\nFor example, to start Shopify theme dev:"
echo -e "\n${GREEN}docker exec -it $CONTAINER_NAME shopify theme dev --store='$SHOPIFY_STORE' --verbose${RESET}"
echo -e "\n\nSHOPIFY_STORE: ${YELLOW}$SHOPIFY_STORE${RESET}"
echo -e "\nTHEME_PRODUCTION_ID: ${YELLOW}$THEME_PRODUCTION_ID${RESET}"
echo -e "\nTHEME_STAGING_ID: ${YELLOW}$THEME_STAGING_ID${RESET}\n\n"
28 changes: 28 additions & 0 deletions scripts/shopify-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if CONTAINER_NAME variable is set
check_variable "CONTAINER_NAME"

# Check if the container is running
if is_container_running "$CONTAINER_NAME"; then
echo -e "Stopping and removing the container ${YELLOW}$CONTAINER_NAME${RESET}...\n"

# Stop the running container
docker stop "$CONTAINER_NAME"

# Remove the container
docker rm "$CONTAINER_NAME"

echo -e "Container ${YELLOW}$CONTAINER_NAME${RESET} has been stopped and removed.\n"
else
echo -e "Container ${YELLOW}$CONTAINER_NAME${RESET} is not running.\n"
fi
52 changes: 52 additions & 0 deletions scripts/shopify-theme-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Load common utility functions and variables
source "$(dirname "$0")/utils.sh"

# Navigate to the project directory
navigate_to_project

# Load environment variables
load_env

# Check if SHOPIFY_STORE and CONTAINER_NAME variables are set
check_variable "SHOPIFY_STORE"
check_variable "CONTAINER_NAME"

# Check if the container is already running
if is_container_running "$CONTAINER_NAME"; then
echo "Container '${YELLOW}$CONTAINER_NAME${RESET}' is already running."
else
# Check if the container exists but is stopped
if docker ps -aq -f name="$CONTAINER_NAME" | grep -q .; then
start_existing_container "$CONTAINER_NAME"
else
run_new_container "$CONTAINER_NAME"

# Check if the container started successfully
if [ $? -eq 0 ]; then
echo -e "Container '${YELLOW}$CONTAINER_NAME${RESET}' is running in detached mode."
else
echo -e "Failed to start the container."
exit 1
fi
fi
fi


docker exec -it "$CONTAINER_NAME" shopify theme check --fail-level=$FAIL_LEVEL

# Capture the exit code of the last command
EXIT_CODE=$?


# Optionally, handle the exit code
if [ $EXIT_CODE -ne 0 ]; then
echo -e "The theme check FAILED to pass the fail level = $FAIL_LEVEL"
echo -e "Exit code: $EXIT_CODE"
# Add any additional error handling or exit the script if needed
exit $EXIT_CODE
else
echo -e "The theme check PASSED, ready for deployment!"

fi
Loading
Loading