Merge pull request #81 from maeng17/Feature/SearchComponent #58
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: React+NginxCICD | |
on: | |
push: | |
branches: | |
- deploy | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
with: | |
ref: deploy | |
- name: Setup Nodejs | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Cache node_modules | |
uses: actions/cache@v4 | |
id: cache-node-modules | |
with: | |
path: node_modules | |
key: ${{ github.ref }}-node-modules-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ github.ref }}-node-modules- | |
- name: Install Dependencies | |
if: steps.cache-node-modules.outputs.cache-hit != 'true' | |
run: | | |
npm ci | |
- name: Env File add | |
run: | | |
touch .env | |
echo ${{ secrets.SECRET_DEV }} | base64 -d >> .env | |
cat .env | |
ls -alrth | |
- name: Build | |
run: | | |
npm run build | |
- name: Nginx Config | |
run: | | |
touch nginx.conf | |
echo "${{ secrets.NGINX_CONF }}" | base64 -d >> nginx.conf | |
- name: SSL Certificate INPUT | |
run: | | |
touch certificate.crt | |
echo "${{ secrets.SSL_MIXED_CERTIFICATE_CRT }}" | base64 -d >> mixed_certificate.crt | |
touch private.key | |
echo "${{ secrets.SSL_PRIVATE_KEY }}" | base64 -d >> private.key | |
- name: Build and push Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:${{ github.sha }} -f Dockerfile . | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:${{ github.sha }} | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: NCP login & Docker image pull and run | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.NCP_HOST }} | |
username: ${{ secrets.NCP_USERNAME }} | |
key: ${{ secrets.NCP_PASSWORD }} | |
port: ${{ secrets.NCP_PORT }} | |
script: | | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
docker stop ${{ secrets.DOCKER_IMAGE_NAME }} || true | |
docker rm ${{ secrets.DOCKER_IMAGE_NAME }} || true | |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:${{ github.sha }} | |
docker run -d -p 80:80 -p 443:443 --add-host ${{secrets.BACK_API_HOST}} --name ${{ secrets.DOCKER_IMAGE_NAME }} ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }}:${{ github.sha }} | |