Fix SSM parameter passing: use JSON files instead of inline parameters
AWS CLI was misinterpreting inline --parameters with embedded paths. Use file:// JSON parameters for all SSM commands to avoid shell quoting issues.
This commit is contained in:
@@ -144,25 +144,14 @@ jobs:
|
||||
- name: Run database migrations
|
||||
if: needs.detect.outputs.migrations == 'true'
|
||||
run: |
|
||||
cat > /tmp/migrate-params.json << 'PARAMS'
|
||||
{"commands":["set -e","cd /tmp","rm -rf repo.tar.gz filamenteka","curl -sf -o repo.tar.gz https://git.demirix.dev/dax/Filamenteka/archive/main.tar.gz","tar xzf repo.tar.gz","mkdir -p /home/ubuntu/filamenteka-api/api /home/ubuntu/filamenteka-api/database/migrations","cp -r filamenteka/database/* /home/ubuntu/filamenteka-api/database/","cp filamenteka/api/migrate.js /home/ubuntu/filamenteka-api/api/migrate.js","rm -rf repo.tar.gz filamenteka","echo Migration files:","ls -la /home/ubuntu/filamenteka-api/database/migrations/","sudo -iu ubuntu bash -c 'cd /home/ubuntu/filamenteka-api && node api/migrate.js'"]}
|
||||
PARAMS
|
||||
CMD_ID=$(aws ssm send-command \
|
||||
--region $AWS_REGION \
|
||||
--instance-ids "$INSTANCE_ID" \
|
||||
--document-name "AWS-RunShellScript" \
|
||||
--parameters 'commands=[
|
||||
"set -e",
|
||||
"cd /tmp",
|
||||
"rm -rf repo.tar.gz filamenteka",
|
||||
"curl -sf -o repo.tar.gz https://git.demirix.dev/dax/Filamenteka/archive/main.tar.gz",
|
||||
"tar xzf repo.tar.gz",
|
||||
"mkdir -p /home/ubuntu/filamenteka-api/api /home/ubuntu/filamenteka-api/database/migrations",
|
||||
"cp -r filamenteka/database/* /home/ubuntu/filamenteka-api/database/",
|
||||
"cp filamenteka/api/migrate.js /home/ubuntu/filamenteka-api/api/migrate.js",
|
||||
"rm -rf repo.tar.gz filamenteka",
|
||||
"echo Migration files:",
|
||||
"ls -la /home/ubuntu/filamenteka-api/database/migrations/",
|
||||
"sudo -iu ubuntu bash -c 'cd /home/ubuntu/filamenteka-api && node api/migrate.js'"
|
||||
]' \
|
||||
--output json \
|
||||
--parameters file:///tmp/migrate-params.json \
|
||||
--query "Command.CommandId" --output text)
|
||||
|
||||
echo "Migration SSM command: $CMD_ID"
|
||||
@@ -202,19 +191,14 @@ jobs:
|
||||
- name: Deploy server.js
|
||||
id: deploy
|
||||
run: |
|
||||
cat > /tmp/deploy-params.json << 'PARAMS'
|
||||
{"commands":["set -e","cd /home/ubuntu/filamenteka-api","cp server.js server.js.backup","curl -sf -o server.js https://git.demirix.dev/dax/Filamenteka/raw/branch/main/api/server.js","sudo systemctl restart node-api","echo API deployed and restarted"]}
|
||||
PARAMS
|
||||
CMD_ID=$(aws ssm send-command \
|
||||
--region $AWS_REGION \
|
||||
--instance-ids "$INSTANCE_ID" \
|
||||
--document-name "AWS-RunShellScript" \
|
||||
--parameters 'commands=[
|
||||
"set -e",
|
||||
"cd /home/ubuntu/filamenteka-api",
|
||||
"cp server.js server.js.backup",
|
||||
"curl -sf -o server.js https://git.demirix.dev/dax/Filamenteka/raw/branch/main/api/server.js",
|
||||
"sudo systemctl restart node-api",
|
||||
"echo API deployed and restarted"
|
||||
]' \
|
||||
--output json \
|
||||
--parameters file:///tmp/deploy-params.json \
|
||||
--query "Command.CommandId" --output text)
|
||||
|
||||
echo "Deploy SSM command: $CMD_ID"
|
||||
@@ -268,14 +252,14 @@ jobs:
|
||||
if: failure() && steps.deploy.outcome == 'success'
|
||||
run: |
|
||||
echo "Rolling back to server.js.backup..."
|
||||
cat > /tmp/rollback-params.json << 'PARAMS'
|
||||
{"commands":["cd /home/ubuntu/filamenteka-api","if [ -f server.js.backup ]; then cp server.js.backup server.js && sudo systemctl restart node-api && echo Rollback complete; else echo No backup found; fi"]}
|
||||
PARAMS
|
||||
aws ssm send-command \
|
||||
--region $AWS_REGION \
|
||||
--instance-ids "$INSTANCE_ID" \
|
||||
--document-name "AWS-RunShellScript" \
|
||||
--parameters 'commands=[
|
||||
"cd /home/ubuntu/filamenteka-api",
|
||||
"if [ -f server.js.backup ]; then cp server.js.backup server.js && sudo systemctl restart node-api && echo Rollback complete; else echo No backup found; fi"
|
||||
]' \
|
||||
--parameters file:///tmp/rollback-params.json \
|
||||
--output json
|
||||
echo "Rollback command sent"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user