CD #52
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: CD | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 16 * * 1,5' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js environment | |
uses: actions/[email protected] | |
with: | |
node-version: lts/Hydrogen | |
- uses: actions/checkout@v2 | |
- run: | | |
touch ./.env | |
echo "${{ secrets.REACT_ENV }}" > ./.env | |
mkdir ./conf/ssl | |
touch ./conf/ssl/fullchain.pem | |
echo "${{ secrets.SSL_FUULCHAIN }}" > ./conf/ssl/fullchain.pem | |
touch ./conf/ssl/privkey.pem | |
echo "${{ secrets.SSL_PRIVATE }}" > ./conf/ssl/privkey.pem | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Docker Hub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Excute Remote SSH Commands Using SSH_PRIVATE_KEY | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
username: ${{ secrets.REMOTE_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
docker stop ${{ secrets.DOCKER_IMAGE_NAME }} | |
docker rm ${{ secrets.DOCKER_IMAGE_NAME }} | |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
docker run -d -p 80:80 -p 443:443 --network=${{ secrets.DOCKER_NETWORK_NAME }} --name ${{ secrets.DOCKER_IMAGE_NAME }} ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_IMAGE_NAME }} | |
docker system prune -f |