diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 000000000..8bf68b2a4 --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,33 @@ +name: Deploy to VPS + +on: + push: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + # Build + - name: Pull latest changes on VPS + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.VPS_HOST }} + USERNAME: ${{ secrets.VPS_DEPLOY_USER }} + PORT: ${{ secrets.VPS_SSH_PORT }} + KEY: ${{ secrets.VPS_SSHKEY }} + script: cd ${{ secrets.VPS_PROJECT_PATH }} && git fetch && git pull + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.VPS_HOST }} + USERNAME: ${{ secrets.VPS_DEPLOY_USER }} + PORT: ${{ secrets.VPS_SSH_PORT }} + KEY: ${{ secrets.VPS_SSHKEY }} + script: cd ${{ secrets.VPS_PROJECT_PATH }} && make deploy-prod \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f7b600511..3393d8cbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,8 @@ -FROM registry.gitlab.com/pages/hugo/hugo_extended:0.101.0 -CMD [ "serve", "-D", "--bind", "0.0.0.0" ] -ENTRYPOINT [ "hugo" ] +FROM registry.gitlab.com/pages/hugo/hugo_extended:0.101.0 as builder +WORKDIR /site +COPY . /site +RUN hugo + +FROM nginx:alpine +RUN rm -rf /usr/share/nginx/html/* +COPY --from=builder /site/public /usr/share/nginx/html \ No newline at end of file diff --git a/Makefile b/Makefile index 55c0026e0..ea566e65a 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ dev: docker build --rm -f Dockerfile -t jb_hugo:latest . - docker run --rm -it -v "$${PWD}":/app -w /app -p $${HOST_IP:-127.0.0.1}:1313:1313 jb_hugo:latest \ No newline at end of file + docker run --rm -it -v "$${PWD}":/app -w /app -p $${HOST_IP:-127.0.0.1}:1313:1313 jb_hugo:latest + +deploy-prod: + docker build -t jb-jbcom . + docker-compose -f ~/docker-compose.yml up -d jb-jbcom + docker image prune -af \ No newline at end of file