fix: Switch from HTTPS token to SSH key authentication for git clone
This commit is contained in:
parent
b08ff7ad83
commit
e7659a4615
@ -187,41 +187,51 @@ jobs:
|
|||||||
|
|
||||||
- name: Deploy to CT109
|
- name: Deploy to CT109
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/deploy_key -p ${{ secrets.CT109_SSH_PORT }} ${{ secrets.CT109_USER }}@${{ secrets.CT109_HOST }} bash -s << ENDSSH
|
# Copy SSH key to CT109 for git access
|
||||||
|
echo "Setting up git SSH access on CT109..."
|
||||||
|
scp -i ~/.ssh/deploy_key -P ${{ secrets.CT109_SSH_PORT }} ~/.ssh/deploy_key ${{ secrets.CT109_USER }}@${{ secrets.CT109_HOST }}:~/.ssh/git_deploy_key
|
||||||
|
|
||||||
|
ssh -i ~/.ssh/deploy_key -p ${{ secrets.CT109_SSH_PORT }} ${{ secrets.CT109_USER }}@${{ secrets.CT109_HOST }} bash -s << 'ENDSSH'
|
||||||
set -e
|
set -e
|
||||||
export VERSION="${{ github.sha }}"
|
export VERSION="${{ github.sha }}"
|
||||||
export GITEA_TOKEN="${{ secrets.GIT_TOKEN }}"
|
|
||||||
|
# Configure SSH for git
|
||||||
|
chmod 600 ~/.ssh/git_deploy_key
|
||||||
|
eval "$(ssh-agent -s)"
|
||||||
|
ssh-add ~/.ssh/git_deploy_key 2>/dev/null || true
|
||||||
|
|
||||||
|
# Add git.silverlabs.uk to known hosts
|
||||||
|
ssh-keyscan -p 2223 git.silverlabs.uk >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||||
|
|
||||||
# Use home directory for deployment
|
# Use home directory for deployment
|
||||||
DEPLOY_DIR=~/littleshop
|
DEPLOY_DIR=~/littleshop
|
||||||
echo "Using deployment directory: \$DEPLOY_DIR"
|
echo "Using deployment directory: $DEPLOY_DIR"
|
||||||
|
|
||||||
# Create deployment directory if it doesn't exist
|
# Create deployment directory if it doesn't exist
|
||||||
mkdir -p "\$DEPLOY_DIR"
|
mkdir -p "$DEPLOY_DIR"
|
||||||
cd "\$DEPLOY_DIR"
|
cd "$DEPLOY_DIR"
|
||||||
|
|
||||||
# Clone or pull latest code with token authentication
|
# Clone or pull latest code via SSH
|
||||||
if [ ! -d .git ]; then
|
if [ ! -d .git ]; then
|
||||||
echo "Cloning repository with authentication..."
|
echo "Cloning repository via SSH..."
|
||||||
rm -rf * # Clean any existing files
|
rm -rf * # Clean any existing files
|
||||||
# Use token as username, random string as password (Gitea format)
|
GIT_SSH_COMMAND="ssh -i ~/.ssh/git_deploy_key -p 2223" git clone ssh://git@git.silverlabs.uk:2223/Jamie/littleshop.git .
|
||||||
git clone https://\${GITEA_TOKEN}:@git.silverlabs.uk/Jamie/littleshop.git .
|
|
||||||
else
|
else
|
||||||
echo "Repository already cloned, pulling latest..."
|
echo "Repository already cloned, pulling latest..."
|
||||||
git fetch origin
|
GIT_SSH_COMMAND="ssh -i ~/.ssh/git_deploy_key -p 2223" git fetch origin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Checking out version: \$VERSION"
|
echo "Checking out version: $VERSION"
|
||||||
git checkout \$VERSION || git checkout main
|
git checkout $VERSION || git checkout main
|
||||||
|
|
||||||
# Build images on CT109
|
# Build images on CT109
|
||||||
echo "Building LittleShop image..."
|
echo "Building LittleShop image..."
|
||||||
docker build --no-cache -t littleshop:\$VERSION .
|
docker build --no-cache -t littleshop:$VERSION .
|
||||||
docker tag littleshop:\$VERSION littleshop:latest
|
docker tag littleshop:$VERSION littleshop:latest
|
||||||
|
|
||||||
echo "Building TeleBot image..."
|
echo "Building TeleBot image..."
|
||||||
docker build --no-cache -t telebot:\$VERSION -f Dockerfile.telebot .
|
docker build --no-cache -t telebot:$VERSION -f Dockerfile.telebot .
|
||||||
docker tag telebot:\$VERSION telebot:latest
|
docker tag telebot:$VERSION telebot:latest
|
||||||
|
|
||||||
# Stop existing containers
|
# Stop existing containers
|
||||||
echo "Stopping existing containers..."
|
echo "Stopping existing containers..."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user