111 lines
3.4 KiB
YAML
111 lines
3.4 KiB
YAML
on: [push]
|
|
jobs:
|
|
build:
|
|
runs-on: docker
|
|
container:
|
|
image: node:latest
|
|
steps:
|
|
- name: Download & Install Docker
|
|
run: |
|
|
unset HISTFILE
|
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
|
sh get-docker.sh
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Login to Forgejo Container Registry
|
|
uses: docker/login-action@v4
|
|
with:
|
|
# NOTE: Used for Forgejo Runner variables
|
|
registry: ${{ vars.REGISTRY_DOMAIN }}
|
|
username: ${{ vars.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
|
|
#- name: Set up QEMU
|
|
# uses: docker/setup-qemu-action@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v4
|
|
|
|
- name: Build and Push the Application
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64 #,linux/arm64
|
|
push: true
|
|
# https://forgejo.org/docs/next/user/actions/reference/#env-1
|
|
tags: ${{ vars.REGISTRY_DOMAIN }}/${{ env.FORGEJO_REPOSITORY }}:app
|
|
file: Dockerfile
|
|
|
|
- name: Logout and Cleanup
|
|
run: |
|
|
docker logout ${{ vars.REGISTRY_DOMAIN }}
|
|
rm -rf ~/.*history
|
|
rm -rf ~/.docker/config.json
|
|
|
|
|
|
#- run: |
|
|
# ls -la
|
|
# echo "test"
|
|
|
|
# Will probably SSH into docker instance
|
|
#
|
|
deploy:
|
|
runs-on: docker
|
|
container:
|
|
image: ubuntu:latest
|
|
steps:
|
|
- name: Prerequisite, install node & docker
|
|
run: |
|
|
# Get Prerequisite Packages
|
|
unset HISTFILE
|
|
apt update && apt install curl -y
|
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
|
|
|
|
\. "$HOME/.nvm/nvm.sh"
|
|
nvm install 24
|
|
|
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
|
sh get-docker.sh
|
|
|
|
echo "$HOME/.nvm/versions/node/v24.15.0/bin/" >> $GITHUB_PATH
|
|
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Write secrets in an .env file
|
|
run: |
|
|
echo ${{ secrets.API_PORT }} >> .env
|
|
echo ${{ secrets.FRONTEND_PORT }} >> .env
|
|
echo ${{ secrets.AI_API_KEY }} >> .env
|
|
|
|
|
|
- name: Setup remote connection and deploy container.
|
|
env:
|
|
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
|
|
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
|
|
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
|
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
|
|
run: |
|
|
# Begin setting up SSH w/ Secrets
|
|
install -m 600 -D /dev/null ~/.ssh/$DEPLOY_USER
|
|
echo $DEPLOY_KEY | base64 -d > ~/.ssh/$DEPLOY_USER
|
|
ssh-keyscan -H -p $DEPLOY_PORT $DEPLOY_HOST > ~/.ssh/known_hosts
|
|
|
|
printf "Host deploy\nPort $DEPLOY_PORT\nHostname $DEPLOY_HOST\nIdentityFile ~/.ssh/$DEPLOY_USER\nUser $DEPLOY_USER" > ~/.ssh/config
|
|
unset DOCKER_HOST
|
|
docker context create deploy --docker "host=ssh://deploy"
|
|
docker context use deploy
|
|
|
|
# Check to see if we have checked out the repo.
|
|
docker compose down
|
|
docker compose pull
|
|
docker compose up -d
|
|
|
|
- name: Start Cleanup
|
|
run: |
|
|
docker context use default
|
|
docker context rm deploy
|
|
rm -rf ~/.ssh ~/.docker ~/.bash_history
|
|
|