fly things
This commit is contained in:
parent
58774baca1
commit
8a38859990
4 changed files with 149 additions and 132 deletions
260
.github/workflows/deploy-k3s.yaml
vendored
260
.github/workflows/deploy-k3s.yaml
vendored
|
|
@ -1,155 +1,155 @@
|
||||||
name: Deploy to K3s
|
# name: Deploy to K3s
|
||||||
|
|
||||||
on:
|
# on:
|
||||||
push:
|
# push:
|
||||||
branches:
|
# branches:
|
||||||
- main # Or your default branch
|
# - main # Or your default branch
|
||||||
|
|
||||||
env:
|
# env:
|
||||||
# Set your image name, adjust if your GitHub username/org is different from the repo owner
|
# # Set your image name, adjust if your GitHub username/org is different from the repo owner
|
||||||
# Or if your repo name is not what you want for the image name.
|
# # Or if your repo name is not what you want for the image name.
|
||||||
IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
# IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
K8S_NAMESPACE: aprs-app
|
# K8S_NAMESPACE: aprs-app
|
||||||
|
|
||||||
jobs:
|
# jobs:
|
||||||
build-and-push-image:
|
# build-and-push-image:
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
permissions:
|
# permissions:
|
||||||
contents: read
|
# contents: read
|
||||||
packages: write # Needed to push to GHCR
|
# packages: write # Needed to push to GHCR
|
||||||
|
|
||||||
steps:
|
# steps:
|
||||||
- name: Tailscale
|
# - name: Tailscale
|
||||||
uses: tailscale/github-action@v3
|
# uses: tailscale/github-action@v3
|
||||||
with:
|
# with:
|
||||||
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
# oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
||||||
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
# oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
||||||
tags: tag:ci
|
# tags: tag:ci
|
||||||
use-cache: "true"
|
# use-cache: "true"
|
||||||
|
|
||||||
- name: Checkout code
|
# - name: Checkout code
|
||||||
uses: actions/checkout@v4
|
# uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up QEMU
|
# - name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
# uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
# - name: Set up Docker Buildx
|
||||||
id: buildx
|
# id: buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
# uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry
|
# - name: Login to GitHub Container Registry
|
||||||
uses: docker/login-action@v3
|
# uses: docker/login-action@v3
|
||||||
with:
|
# with:
|
||||||
registry: ghcr.io
|
# registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
# username: ${{ github.actor }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
# password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
# - name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
# id: meta
|
||||||
uses: docker/metadata-action@v5
|
# uses: docker/metadata-action@v5
|
||||||
with:
|
# with:
|
||||||
images: ${{ env.IMAGE_NAME }}
|
# images: ${{ env.IMAGE_NAME }}
|
||||||
tags: |
|
# tags: |
|
||||||
type=sha,prefix=
|
# type=sha,prefix=
|
||||||
type=raw,value=latest,enable={{is_default_branch}}
|
# type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
# - name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v5
|
# uses: docker/build-push-action@v5
|
||||||
with:
|
# with:
|
||||||
context: .
|
# context: .
|
||||||
push: true
|
# push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
# tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
# labels: ${{ steps.meta.outputs.labels }}
|
||||||
cache-from: type=gha
|
# cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
# cache-to: type=gha,mode=max
|
||||||
|
|
||||||
deploy-to-k3s:
|
# deploy-to-k3s:
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
needs: build-and-push-image
|
# needs: build-and-push-image
|
||||||
if: github.ref == 'refs/heads/main' # Only deploy from main branch
|
# if: github.ref == 'refs/heads/main' # Only deploy from main branch
|
||||||
|
|
||||||
steps:
|
# steps:
|
||||||
- name: Checkout code
|
# - name: Checkout code
|
||||||
uses: actions/checkout@v4
|
# uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Tailscale
|
# - name: Tailscale
|
||||||
uses: tailscale/github-action@v3
|
# uses: tailscale/github-action@v3
|
||||||
with:
|
# with:
|
||||||
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
# oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
|
||||||
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
# oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
|
||||||
tags: tag:ci
|
# tags: tag:ci
|
||||||
use-cache: "true"
|
# use-cache: "true"
|
||||||
|
|
||||||
- name: Set up Kubeconfig
|
# - name: Set up Kubeconfig
|
||||||
uses: azure/setup-kubectl@v3 # A popular action for kubectl
|
# uses: azure/setup-kubectl@v3 # A popular action for kubectl
|
||||||
# Alternatively, can do this manually:
|
# # Alternatively, can do this manually:
|
||||||
# run: |
|
# # run: |
|
||||||
# mkdir -p $HOME/.kube
|
# # mkdir -p $HOME/.kube
|
||||||
# echo "${{ secrets.KUBE_CONFIG_DATA }}" | base64 -d > $HOME/.kube/config
|
# # echo "${{ secrets.KUBE_CONFIG_DATA }}" | base64 -d > $HOME/.kube/config
|
||||||
# chmod 600 $HOME/.kube/config
|
# # chmod 600 $HOME/.kube/config
|
||||||
|
|
||||||
- name: Install Kustomize (optional, but good for managing overlays)
|
# - name: Install Kustomize (optional, but good for managing overlays)
|
||||||
run: |-
|
# run: |-
|
||||||
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
|
# curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
|
||||||
sudo mv kustomize /usr/local/bin/
|
# sudo mv kustomize /usr/local/bin/
|
||||||
# If not using kustomize, this step can be removed.
|
# # If not using kustomize, this step can be removed.
|
||||||
# For now, we'll use kubectl apply -f directly for simplicity.
|
# # For now, we'll use kubectl apply -f directly for simplicity.
|
||||||
|
|
||||||
- name: Substitute Image Tag in Kubernetes Manifest
|
# - name: Substitute Image Tag in Kubernetes Manifest
|
||||||
run: |
|
# run: |
|
||||||
# The meta step outputs tags like: ghcr.io/owner/repo:sha-xxxxxxx,ghcr.io/owner/repo:latest
|
# # The meta step outputs tags like: ghcr.io/owner/repo:sha-xxxxxxx,ghcr.io/owner/repo:latest
|
||||||
# We need to pick the SHA-based tag.
|
# # We need to pick the SHA-based tag.
|
||||||
# github.sha gives the commit SHA, which is perfect for a specific tag.
|
# # github.sha gives the commit SHA, which is perfect for a specific tag.
|
||||||
ACTUAL_IMAGE_NAME_WITH_TAG="${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
# ACTUAL_IMAGE_NAME_WITH_TAG="${{ env.IMAGE_NAME }}:${{ github.sha }}"
|
||||||
echo "Using image: $ACTUAL_IMAGE_NAME_WITH_TAG"
|
# echo "Using image: $ACTUAL_IMAGE_NAME_WITH_TAG"
|
||||||
|
|
||||||
# Create a temporary deployment file for substitution
|
# # Create a temporary deployment file for substitution
|
||||||
cp k8s/app-deployment.yaml k8s/app-deployment-processed.yaml
|
# cp k8s/app-deployment.yaml k8s/app-deployment-processed.yaml
|
||||||
|
|
||||||
# Replace placeholder image in the processed file
|
# # Replace placeholder image in the processed file
|
||||||
# Using a different delimiter for sed due to slashes in image name
|
# # Using a different delimiter for sed due to slashes in image name
|
||||||
sed -i "s|your-ghcr-username/aprs-app:latest|$ACTUAL_IMAGE_NAME_WITH_TAG|g" k8s/app-deployment-processed.yaml
|
# sed -i "s|your-ghcr-username/aprs-app:latest|$ACTUAL_IMAGE_NAME_WITH_TAG|g" k8s/app-deployment-processed.yaml
|
||||||
# Ensure initContainer is also updated (duplicate sed command is fine, ensures both are hit if structure changes)
|
# # Ensure initContainer is also updated (duplicate sed command is fine, ensures both are hit if structure changes)
|
||||||
sed -i "s|your-ghcr-username/aprs-app:latest|$ACTUAL_IMAGE_NAME_WITH_TAG|g" k8s/app-deployment-processed.yaml
|
# sed -i "s|your-ghcr-username/aprs-app:latest|$ACTUAL_IMAGE_NAME_WITH_TAG|g" k8s/app-deployment-processed.yaml
|
||||||
|
|
||||||
- name: Apply Kubernetes manifests
|
# - name: Apply Kubernetes manifests
|
||||||
env:
|
# env:
|
||||||
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} # Pass secret to env for kubectl if not using azure/setup-kubectl
|
# KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} # Pass secret to env for kubectl if not using azure/setup-kubectl
|
||||||
run: |
|
# run: |
|
||||||
# Ensure Kubeconfig is set up if not using an action
|
# # Ensure Kubeconfig is set up if not using an action
|
||||||
if [ ! -f "$HOME/.kube/config" ] && [ -n "$KUBE_CONFIG_DATA" ]; then
|
# if [ ! -f "$HOME/.kube/config" ] && [ -n "$KUBE_CONFIG_DATA" ]; then
|
||||||
mkdir -p $HOME/.kube
|
# mkdir -p $HOME/.kube
|
||||||
echo "$KUBE_CONFIG_DATA" | base64 -d > $HOME/.kube/config
|
# echo "$KUBE_CONFIG_DATA" | base64 -d > $HOME/.kube/config
|
||||||
chmod 600 $HOME/.kube/config
|
# chmod 600 $HOME/.kube/config
|
||||||
echo "Kubeconfig set up manually."
|
# echo "Kubeconfig set up manually."
|
||||||
elif [ ! -f "$HOME/.kube/config" ] && [ -z "$KUBE_CONFIG_DATA" ] && [ -z "$(kubectl config current-context 2>/dev/null)" ]; then
|
# elif [ ! -f "$HOME/.kube/config" ] && [ -z "$KUBE_CONFIG_DATA" ] && [ -z "$(kubectl config current-context 2>/dev/null)" ]; then
|
||||||
echo "Kubeconfig not found. KUBE_CONFIG_DATA secret is not set or empty, and no context is set by azure/setup-kubectl."
|
# echo "Kubeconfig not found. KUBE_CONFIG_DATA secret is not set or empty, and no context is set by azure/setup-kubectl."
|
||||||
exit 1
|
# exit 1
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# Apply namespace first
|
# # Apply namespace first
|
||||||
kubectl apply -f k8s/namespace.yaml --insecure-skip-tls-verify
|
# kubectl apply -f k8s/namespace.yaml --insecure-skip-tls-verify
|
||||||
|
|
||||||
# Apply secrets if a real one exists (checking for secrets.yaml, not secrets.yaml.example)
|
# # Apply secrets if a real one exists (checking for secrets.yaml, not secrets.yaml.example)
|
||||||
# This assumes you will create the actual secrets.yaml in a secure way or it's handled by another process.
|
# # This assumes you will create the actual secrets.yaml in a secure way or it's handled by another process.
|
||||||
# For this automated workflow, we'll only apply if the example isn't the only one.
|
# # For this automated workflow, we'll only apply if the example isn't the only one.
|
||||||
# A better way is to manage actual secrets outside the repo & this flow.
|
# # A better way is to manage actual secrets outside the repo & this flow.
|
||||||
# For now, we expect secrets to be pre-applied or managed via a more secure mechanism.
|
# # For now, we expect secrets to be pre-applied or managed via a more secure mechanism.
|
||||||
# So, we will NOT apply secrets.yaml.example here. The user must ensure secrets are present.
|
# # So, we will NOT apply secrets.yaml.example here. The user must ensure secrets are present.
|
||||||
echo "Ensuring secrets are present in namespace ${{ env.K8S_NAMESPACE }}. This workflow does not apply them directly from a .example file."
|
# echo "Ensuring secrets are present in namespace ${{ env.K8S_NAMESPACE }}. This workflow does not apply them directly from a .example file."
|
||||||
|
|
||||||
# Apply other resources
|
# # Apply other resources
|
||||||
kubectl apply -f k8s/postgres-pvc.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
# kubectl apply -f k8s/postgres-pvc.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
||||||
# It's good practice to check if a resource exists before applying or use --overwrite, but apply usually handles this.
|
# # It's good practice to check if a resource exists before applying or use --overwrite, but apply usually handles this.
|
||||||
# For sensitive or stateful things like Postgres, ensure your strategy for updates is clear.
|
# # For sensitive or stateful things like Postgres, ensure your strategy for updates is clear.
|
||||||
kubectl apply -f k8s/postgres-deployment.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
# kubectl apply -f k8s/postgres-deployment.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
||||||
kubectl apply -f k8s/postgres-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
# kubectl apply -f k8s/postgres-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
||||||
|
|
||||||
# Apply the processed app deployment
|
# # Apply the processed app deployment
|
||||||
kubectl apply -f k8s/app-deployment-processed.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
# kubectl apply -f k8s/app-deployment-processed.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
||||||
kubectl apply -f k8s/app-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
# kubectl apply -f k8s/app-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify
|
||||||
|
|
||||||
echo "Deployment to K3s initiated."
|
# echo "Deployment to K3s initiated."
|
||||||
|
|
||||||
# Optional: Wait for rollout to complete
|
# # Optional: Wait for rollout to complete
|
||||||
# kubectl rollout status deployment/aprs-app-deployment --namespace=${{ env.K8S_NAMESPACE }} --timeout=120s --insecure-skip-tls-verify
|
# # kubectl rollout status deployment/aprs-app-deployment --namespace=${{ env.K8S_NAMESPACE }} --timeout=120s --insecure-skip-tls-verify
|
||||||
|
|
|
||||||
18
.github/workflows/fly-deploy.yml
vendored
Normal file
18
.github/workflows/fly-deploy.yml
vendored
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
|
||||||
|
|
||||||
|
name: Fly Deploy
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
name: Deploy app
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
concurrency: deploy-group # optional: ensure only one action runs at a time
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: superfly/flyctl-actions/setup-flyctl@master
|
||||||
|
- run: flyctl deploy --remote-only
|
||||||
|
env:
|
||||||
|
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
|
||||||
|
|
@ -44,7 +44,6 @@ if config_env() == :prod do
|
||||||
|
|
||||||
host = System.get_env("PHX_HOST") || "example.com"
|
host = System.get_env("PHX_HOST") || "example.com"
|
||||||
port = String.to_integer(System.get_env("PORT") || "4000")
|
port = String.to_integer(System.get_env("PORT") || "4000")
|
||||||
app_name = "aprs"
|
|
||||||
|
|
||||||
config :aprs, Aprs.Repo,
|
config :aprs, Aprs.Repo,
|
||||||
# ssl: true,
|
# ssl: true,
|
||||||
|
|
|
||||||
2
fly.toml
2
fly.toml
|
|
@ -1,4 +1,4 @@
|
||||||
# fly.toml app configuration file generated for aprs-me on 2025-01-22T13:50:44-06:00
|
# fly.toml app configuration file generated for aprs-me on 2025-06-13T15:08:29-05:00
|
||||||
#
|
#
|
||||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue