diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a69a8c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +# flyctl launch added from .gitignore +**/.idea +fly.toml 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/Dockerfile b/Dockerfile index 969242e..6aa29f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,32 @@ +# Builder FROM golang:1.19-alpine as builder + WORKDIR /app + COPY . ./ RUN go mod download RUN go build + +# Release FROM alpine:latest -RUN apk update && apk add ca-certificates iptables ip6tables bash bind-tools jq && rm -rf /var/cache/apk/* + +ENV TSFILE=tailscale_1.70.0_amd64.tgz +ENV DNSPROXYFILE=dnsproxy-linux-amd64-v0.72.1.tar.gz +ENV DNSPROXYVERSION=v0.72.1 WORKDIR /app -COPY . ./ -ENV TSFILE=tailscale_1.30.2_amd64.tgz -ENV DNSPROXYFILE=dnsproxy-linux-amd64-v0.45.2.tar.gz -ENV DNSPROXYVERSION=v0.45.2 + +RUN apk update && apk add ca-certificates iptables ip6tables bash bind-tools jq && rm -rf /var/cache/apk/* RUN wget https://pkgs.tailscale.com/stable/${TSFILE} && tar xzf ${TSFILE} --strip-components=1 RUN wget https://github.com/AdguardTeam/dnsproxy/releases/download/${DNSPROXYVERSION}/${DNSPROXYFILE} && tar xzf ${DNSPROXYFILE} --strip-components=1 + COPY --from=builder /app/tailscale-router /app/tailscale-router -COPY . ./ +# Copy and run tailscale init script, default nginx config +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh RUN mkdir -p /var/run/tailscale /var/cache/tailscale /var/lib/tailscale -CMD ["/app/start.sh"] +CMD ["/usr/local/bin/docker-entrypoint.sh"] diff --git a/start.sh b/docker-entrypoint.sh similarity index 99% rename from start.sh rename to docker-entrypoint.sh index e6be45b..6473110 100755 --- a/start.sh +++ b/docker-entrypoint.sh @@ -13,5 +13,4 @@ else exit 1 fi - tail -f /dev/null diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..f9931a0 --- /dev/null +++ b/fly.toml @@ -0,0 +1,19 @@ +# fly.toml app configuration file generated for bcit-ltc-subnet-router-crimson-sun-1032 on 2024-08-08T12:50:41-07:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'bcit-ltc-subnet-router' +primary_region = 'yyz' + +[env] + TS_HOSTNAME = 'bcit-ltc-subnet-router' + +[build] + +[[vm]] + size = 'shared-cpu-1x' + +[deploy] +# release_command = " tailscale down" + strategy = "canary" \ No newline at end of file diff --git a/main.go b/main.go index 120193c..91d487d 100644 --- a/main.go +++ b/main.go @@ -87,7 +87,7 @@ func main() { } fmt.Println("tailscale-router: running tailscale up") - upcmd := exec.Command("bash", "-c", fmt.Sprintf("%s up --authkey=%s --advertise-routes=%s", tailscale_binary_path, key, subnet)) + upcmd := exec.Command("bash", "-c", fmt.Sprintf("%s up --authkey=%s --hostname=bcit-ltc-subnet-router --advertise-routes=%s", tailscale_binary_path, key, subnet)) err = upcmd.Run() if err != nil { panic(err)