Merge branch 'One-Click-Auth:dev-branch' into dev-branch #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Docker Image to dev_EC2 | |
on: | |
push: | |
branches: | |
- dev-branch | |
jobs: | |
deploy_dev: | |
name: Build and Deploy to Dev | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Build Docker image with secrets as build args | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_SECRET: ${{ secrets.DOCKER_SECRET }} | |
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} | |
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} | |
ACCESS_KEY_ID: ${{ secrets._ACCESS_KEY_ID }} | |
S3_BUCKET: ${{ secrets._S3_BUCKET }} | |
S3_REGION: ${{ secrets._S3_REGION }} | |
SECRET_ACCESS_KEY: ${{ secrets._SECRET_ACCESS_KEY }} | |
NEXT_PUBLIC_AES_KEY: ${{ secrets.NEXT_PUBLIC_AES_KEY }} | |
NEXT_PUBLIC_CS_CAPTCHA_SECRET: ${{ secrets.NEXT_PUBLIC_CS_CAPTCHA_SECRET }} | |
run: | | |
echo ${{ secrets.DOCKER_SECRET }} | docker login -u moonlightnexus --password-stdin | |
# Build the Docker image with build arguments | |
docker build \ | |
--build-arg NEXTAUTH_SECRET=${NEXTAUTH_SECRET} \ | |
--build-arg NEXTAUTH_URL=${NEXTAUTH_URL} \ | |
--build-arg ACCESS_KEY_ID=${ACCESS_KEY_ID} \ | |
--build-arg S3_BUCKET=${S3_BUCKET} \ | |
--build-arg S3_REGION=${S3_REGION} \ | |
--build-arg SECRET_ACCESS_KEY=${SECRET_ACCESS_KEY} \ | |
--build-arg NEXT_PUBLIC_AES_KEY=${NEXT_PUBLIC_AES_KEY} \ | |
--build-arg NEXT_PUBLIC_CS_CAPTCHA_SECRET=${NEXT_PUBLIC_CS_CAPTCHA_SECRET} \ | |
-t my-nextjs-app . | |
docker tag my-nextjs-app:latest moonlightnexus/internal-trustauthx:latest | |
docker push moonlightnexus/internal-trustauthx:latest | |
- name: Deploy to Dev using SSH | |
env: | |
AWS_EC2_PEM: ${{ secrets.AWS_EC2_DEV_PEM }} | |
AWS_EC2_PUBLIC_IP: ${{ secrets.AWS_EC2_DEV_PUBLIC_IP }} | |
AWS_EC2_USERNAME: ${{ secrets.AWS_EC2_DEV_USERNAME }} | |
run: | | |
echo "$AWS_EC2_PEM" > private.pem && chmod 600 private.pem | |
cat << 'EOF' > deploy_script.sh | |
#!/bin/bash | |
sudo docker stop nextjs || true | |
sudo docker rm nextjs || true | |
sudo docker pull moonlightnexus/internal-trustauthx | |
sudo docker run -d --name nextjs -p 3000:3000 moonlightnexus/internal-trustauthx | |
EOF | |
scp -o StrictHostKeyChecking=no -i private.pem deploy_script.sh ${AWS_EC2_USERNAME}@${AWS_EC2_PUBLIC_IP}:~/deploy_script.sh | |
ssh -o StrictHostKeyChecking=no -i private.pem ${AWS_EC2_USERNAME}@${AWS_EC2_PUBLIC_IP} 'chmod +x ~/deploy_script.sh && ~/deploy_script.sh' |