Skip to content

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
  • Loading branch information
dotslashf committed Sep 7, 2024
1 parent 6c9a6d4 commit 760bba5
Showing 1 changed file with 14 additions and 25 deletions.
39 changes: 14 additions & 25 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,40 +46,29 @@ jobs:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Deploy to SSH server
env:
REGION: ${{ secrets.GCE_REGION }}
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA: ${{ github.sha }}
run: |
# Base64 encode the GCP_SA_KEY to avoid issues with special characters
GCP_SA_KEY_BASE64=$(echo '${{ secrets.GCP_SA_KEY }}' | base64 -w 0)
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
REGION=${{ secrets.GCE_REGION }}
PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}
GITHUB_SHA=${{ github.sha }}
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}
cd ${{ secrets.PROJECT_PATH }}
if [ ! -f docker-compose.yml ]; then
echo "docker-compose.yml not found in ${{ secrets.PROJECT_PATH }}"
exit 1
fi
# Decode the GCP_SA_KEY and save it to a file
echo "$GCP_SA_KEY_BASE64" | base64 --decode > gcp-sa-key.json
# Authenticate Docker with Google Cloud
cat gcp-sa-key.json | docker login -u _json_key --password-stdin https://${{ secrets.GCE_REGION }}-docker.pkg.dev
# Pull the latest image from Google Artifact Registry
docker pull ${REGION}-docker.pkg.dev/${PROJECT_ID}/arsip-template/app:${GITHUB_SHA}
# Update docker-compose.yml to use the key file
sed -i 's|GCP_SA_KEY=.*|GCP_SA_KEY=/path/to/gcp-sa-key.json|g' docker-compose.yml
# Update the docker-compose.yml file with the new image tag
sed -i "s|image: .*|image: ${REGION}-docker.pkg.dev/${PROJECT_ID}/arsip-template/app:${GITHUB_SHA}|g" docker-compose.yml
# Set other environment variables
sed -i 's|REGION=.*|REGION=${{ env.REGION }}|g' docker-compose.yml
sed -i 's|PROJECT_ID=.*|PROJECT_ID=${{ env.PROJECT_ID }}|g' docker-compose.yml
sed -i 's|GITHUB_SHA=.*|GITHUB_SHA=${{ github.sha }}|g' docker-compose.yml
# Pull and restart containers
docker-compose pull
# Restart the Docker Compose services
docker-compose down
docker-compose up -d
# Clean up the key file
rm gcp-sa-key.json

0 comments on commit 760bba5

Please sign in to comment.