84 lines
2.7 KiB
YAML
84 lines
2.7 KiB
YAML
name: Winsomnia GitOps Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "*"
|
|
|
|
jobs:
|
|
build-and-push:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine environment
|
|
id: envdetect
|
|
run: |
|
|
REPO_SLUG=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
if [[ "${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main" ]]; then
|
|
DEPLOY_ENV="prod"
|
|
else
|
|
DEPLOY_ENV="dev"
|
|
fi
|
|
|
|
echo "repo_slug=$REPO_SLUG" >> $GITHUB_OUTPUT
|
|
echo "deploy_env=$DEPLOY_ENV" >> $GITHUB_OUTPUT
|
|
|
|
- name: Enable Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Winsomnia Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ secrets.WINSOMNIA_REGISTRY }}
|
|
username: ${{ secrets.WINSOMNIA_REGISTRY_USER }}
|
|
password: ${{ secrets.WINSOMNIA_REGISTRY_TOKEN }}
|
|
|
|
- name: Build & Push Docker Image
|
|
id: build
|
|
env:
|
|
DOCKER_BUILDKIT: 1
|
|
WINSOMNIA_NUGET_USERNAME: ${{ secrets.WINSOMNIA_NUGET_USERNAME }}
|
|
WINSOMNIA_NUGET_TOKEN: ${{ secrets.WINSOMNIA_NUGET_TOKEN }}
|
|
WINSOMNIA_NUGET_SOURCE: ${{ secrets.WINSOMNIA_NUGET_SOURCE }}
|
|
run: |
|
|
IMAGE="${{ secrets.WINSOMNIA_REGISTRY }}/winsomnia/${{ steps.envdetect.outputs.repo_slug }}:${GITHUB_REF_NAME}"
|
|
|
|
docker build \
|
|
--secret id=nuget_username,env=WINSOMNIA_NUGET_USERNAME \
|
|
--secret id=nuget_token,env=WINSOMNIA_NUGET_TOKEN \
|
|
--secret id=nuget_source,env=WINSOMNIA_NUGET_SOURCE \
|
|
-t "$IMAGE" .
|
|
|
|
docker push "$IMAGE"
|
|
|
|
echo "image=$IMAGE" >> $GITHUB_OUTPUT
|
|
|
|
outputs:
|
|
image: ${{ steps.build.outputs.image }}
|
|
repo_slug: ${{ steps.envdetect.outputs.repo_slug }}
|
|
deploy_env: ${{ steps.envdetect.outputs.deploy_env }}
|
|
|
|
deploy:
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Add deploy SSH key
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.WINSOMNIA_DEPLOY_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
|
|
- name: Add host key
|
|
run: ssh-keyscan ${{ secrets.WINSOMNIA_DEPLOY_HOST }} >> ~/.ssh/known_hosts
|
|
|
|
- name: Run deploy.sh on server
|
|
run: |
|
|
REMOTE_PATH="${{ secrets.WINSOMNIA_INFRA_ROOT }}/${{ needs.build-and-push.outputs.repo_slug }}/${{ needs.build-and-push.outputs.deploy_env }}"
|
|
|
|
ssh ${{ secrets.WINSOMNIA_DEPLOY_USER }}@${{ secrets.WINSOMNIA_DEPLOY_HOST }} \
|
|
"${REMOTE_PATH}/deploy.sh '${{ needs.build-and-push.outputs.image }}'" |