From 8a388599904b0b358c783f84ab762e7c264f6080 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 13 Jun 2025 15:10:29 -0500 Subject: [PATCH] fly things --- .github/workflows/deploy-k3s.yaml | 260 +++++++++++++++--------------- .github/workflows/fly-deploy.yml | 18 +++ config/runtime.exs | 1 - fly.toml | 2 +- 4 files changed, 149 insertions(+), 132 deletions(-) create mode 100644 .github/workflows/fly-deploy.yml diff --git a/.github/workflows/deploy-k3s.yaml b/.github/workflows/deploy-k3s.yaml index 8e2305d..76f9f02 100644 --- a/.github/workflows/deploy-k3s.yaml +++ b/.github/workflows/deploy-k3s.yaml @@ -1,155 +1,155 @@ -name: Deploy to K3s +# name: Deploy to K3s -on: - push: - branches: - - main # Or your default branch +# on: +# push: +# branches: +# - main # Or your default branch -env: - # 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. - IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} - K8S_NAMESPACE: aprs-app +# env: +# # 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. +# IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} +# K8S_NAMESPACE: aprs-app -jobs: - build-and-push-image: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write # Needed to push to GHCR +# jobs: +# build-and-push-image: +# runs-on: ubuntu-latest +# permissions: +# contents: read +# packages: write # Needed to push to GHCR - steps: - - name: Tailscale - uses: tailscale/github-action@v3 - with: - oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} - oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} - tags: tag:ci - use-cache: "true" +# steps: +# - name: Tailscale +# uses: tailscale/github-action@v3 +# with: +# oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} +# oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} +# tags: tag:ci +# use-cache: "true" - - name: Checkout code - uses: actions/checkout@v4 +# - name: Checkout code +# uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 +# - name: Set up QEMU +# uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 +# - name: Set up Docker Buildx +# id: buildx +# uses: docker/setup-buildx-action@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} +# - name: Login to GitHub Container Registry +# uses: docker/login-action@v3 +# with: +# registry: ghcr.io +# username: ${{ github.actor }} +# password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - type=sha,prefix= - type=raw,value=latest,enable={{is_default_branch}} +# - name: Extract metadata (tags, labels) for Docker +# id: meta +# uses: docker/metadata-action@v5 +# with: +# images: ${{ env.IMAGE_NAME }} +# tags: | +# type=sha,prefix= +# type=raw,value=latest,enable={{is_default_branch}} - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max +# - name: Build and push Docker image +# uses: docker/build-push-action@v5 +# with: +# context: . +# push: true +# tags: ${{ steps.meta.outputs.tags }} +# labels: ${{ steps.meta.outputs.labels }} +# cache-from: type=gha +# cache-to: type=gha,mode=max - deploy-to-k3s: - runs-on: ubuntu-latest - needs: build-and-push-image - if: github.ref == 'refs/heads/main' # Only deploy from main branch +# deploy-to-k3s: +# runs-on: ubuntu-latest +# needs: build-and-push-image +# if: github.ref == 'refs/heads/main' # Only deploy from main branch - steps: - - name: Checkout code - uses: actions/checkout@v4 +# steps: +# - name: Checkout code +# uses: actions/checkout@v4 - - name: Tailscale - uses: tailscale/github-action@v3 - with: - oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} - oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} - tags: tag:ci - use-cache: "true" +# - name: Tailscale +# uses: tailscale/github-action@v3 +# with: +# oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }} +# oauth-secret: ${{ secrets.TS_OAUTH_SECRET }} +# tags: tag:ci +# use-cache: "true" - - name: Set up Kubeconfig - uses: azure/setup-kubectl@v3 # A popular action for kubectl - # Alternatively, can do this manually: - # run: | - # mkdir -p $HOME/.kube - # echo "${{ secrets.KUBE_CONFIG_DATA }}" | base64 -d > $HOME/.kube/config - # chmod 600 $HOME/.kube/config +# - name: Set up Kubeconfig +# uses: azure/setup-kubectl@v3 # A popular action for kubectl +# # Alternatively, can do this manually: +# # run: | +# # mkdir -p $HOME/.kube +# # echo "${{ secrets.KUBE_CONFIG_DATA }}" | base64 -d > $HOME/.kube/config +# # chmod 600 $HOME/.kube/config - - name: Install Kustomize (optional, but good for managing overlays) - run: |- - curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash - sudo mv kustomize /usr/local/bin/ - # If not using kustomize, this step can be removed. - # For now, we'll use kubectl apply -f directly for simplicity. +# - name: Install Kustomize (optional, but good for managing overlays) +# run: |- +# curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash +# sudo mv kustomize /usr/local/bin/ +# # If not using kustomize, this step can be removed. +# # For now, we'll use kubectl apply -f directly for simplicity. - - name: Substitute Image Tag in Kubernetes Manifest - run: | - # 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. - # github.sha gives the commit SHA, which is perfect for a specific tag. - ACTUAL_IMAGE_NAME_WITH_TAG="${{ env.IMAGE_NAME }}:${{ github.sha }}" - echo "Using image: $ACTUAL_IMAGE_NAME_WITH_TAG" +# - name: Substitute Image Tag in Kubernetes Manifest +# run: | +# # 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. +# # github.sha gives the commit SHA, which is perfect for a specific tag. +# ACTUAL_IMAGE_NAME_WITH_TAG="${{ env.IMAGE_NAME }}:${{ github.sha }}" +# echo "Using image: $ACTUAL_IMAGE_NAME_WITH_TAG" - # Create a temporary deployment file for substitution - cp k8s/app-deployment.yaml k8s/app-deployment-processed.yaml +# # Create a temporary deployment file for substitution +# cp k8s/app-deployment.yaml k8s/app-deployment-processed.yaml - # Replace placeholder image in the processed file - # 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 - # 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 +# # Replace placeholder image in the processed file +# # 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 +# # 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 - - name: Apply Kubernetes manifests - env: - KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} # Pass secret to env for kubectl if not using azure/setup-kubectl - run: | - # Ensure Kubeconfig is set up if not using an action - if [ ! -f "$HOME/.kube/config" ] && [ -n "$KUBE_CONFIG_DATA" ]; then - mkdir -p $HOME/.kube - echo "$KUBE_CONFIG_DATA" | base64 -d > $HOME/.kube/config - chmod 600 $HOME/.kube/config - echo "Kubeconfig set up manually." - 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." - exit 1 - fi +# - name: Apply Kubernetes manifests +# env: +# KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} # Pass secret to env for kubectl if not using azure/setup-kubectl +# run: | +# # Ensure Kubeconfig is set up if not using an action +# if [ ! -f "$HOME/.kube/config" ] && [ -n "$KUBE_CONFIG_DATA" ]; then +# mkdir -p $HOME/.kube +# echo "$KUBE_CONFIG_DATA" | base64 -d > $HOME/.kube/config +# chmod 600 $HOME/.kube/config +# echo "Kubeconfig set up manually." +# 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." +# exit 1 +# fi - # Apply namespace first - kubectl apply -f k8s/namespace.yaml --insecure-skip-tls-verify +# # Apply namespace first +# 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) - # 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. - # 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. - # 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." +# # 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. +# # 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. +# # 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. +# echo "Ensuring secrets are present in namespace ${{ env.K8S_NAMESPACE }}. This workflow does not apply them directly from a .example file." - # Apply other resources - 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. - # 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-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify +# # Apply other resources +# 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. +# # 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-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify - # 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-service.yaml --namespace=${{ env.K8S_NAMESPACE }} --insecure-skip-tls-verify +# # 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-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 - # kubectl rollout status deployment/aprs-app-deployment --namespace=${{ env.K8S_NAMESPACE }} --timeout=120s --insecure-skip-tls-verify +# # Optional: Wait for rollout to complete +# # kubectl rollout status deployment/aprs-app-deployment --namespace=${{ env.K8S_NAMESPACE }} --timeout=120s --insecure-skip-tls-verify diff --git a/.github/workflows/fly-deploy.yml b/.github/workflows/fly-deploy.yml new file mode 100644 index 0000000..b0c246e --- /dev/null +++ b/.github/workflows/fly-deploy.yml @@ -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 }} diff --git a/config/runtime.exs b/config/runtime.exs index 93fe43a..4c53db9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -44,7 +44,6 @@ if config_env() == :prod do host = System.get_env("PHX_HOST") || "example.com" port = String.to_integer(System.get_env("PORT") || "4000") - app_name = "aprs" config :aprs, Aprs.Repo, # ssl: true, diff --git a/fly.toml b/fly.toml index 66791d8..2309998 100644 --- a/fly.toml +++ b/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. #