fbla-cs-competition/.forgejo/workflows/start.yaml
devaine 50256abceb
All checks were successful
/ build (push) Successful in 2m40s
/ deploy (push) Successful in 1m48s
fix(workflow): properly added environment variables to deployment
2026-05-11 18:00:12 -05:00

105 lines
3.2 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:
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"
deploy:
runs-on: docker
container:
image: ubuntu:latest
steps:
- name: Prerequisite, install node & docker
run: |
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: 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
# Add secrets to the .env file
echo ${{ secrets.API_PORT }} >> .env
echo ${{ secrets.FRONTEND_PORT }} >> .env
echo ${{ secrets.AI_API_KEY }} >> .env
# 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 .env