portfolio/.gitea/workflows/publish.yml
Ryan Freeman 80dee58abe
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m41s
Update workflow
2024-11-17 20:00:38 +00:00

61 lines
1.8 KiB
YAML

name: Build And Publish
run-name: ${{ gitea.actor }} runs ci pipeline
on:
schedule:
- cron: '59 23 * * *'
push:
branches:
- 'main'
jobs:
BuildAndPublish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Use Node.js
uses: https://github.com/actions/setup-node@v3
with:
node-version: '18.17.0'
- name: Decrypt secrets
run: ./decrypt_secrets.sh
env:
SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_PASSWORD}}
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
with:
config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Build and push Docker image
uses: https://github.com/docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{secrets.DOCKER_HUB_USERNAME}}/${{vars.REPO_NAME}}:latest
- name: Stop and remove old Docker container
continue-on-error: true
run: |
sudo docker stop ${{vars.REPO_NAME}}
sudo docker rm ${{vars.REPO_NAME}}
- name: Pull new image and start Docker container
run: |
sudo docker pull ${{secrets.DOCKER_HUB_USERNAME}}/${{vars.REPO_NAME}}:latest
sudo docker run -d --restart unless-stopped \
--env-file ./.env \
--name ${{vars.REPO_NAME}} \
-p ${{vars.SERVER_IP}}:3000:3000 \
${{secrets.DOCKER_HUB_USERNAME}}/${{vars.REPO_NAME}}:latest