From 76b07000ad323321e9b992a2f97da4d420a57a4f Mon Sep 17 00:00:00 2001 From: "opsmaru[bot]" <73541519+opsmaru[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 04:39:13 +0000 Subject: [PATCH 1/4] Deployment configuration base-elixir-phoenix for polar. --- .github/workflows/deployment.yml | 79 ++++++++++++++++++++++++++++++ instellar.yml | 82 ++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 .github/workflows/deployment.yml create mode 100644 instellar.yml diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml new file mode 100644 index 0000000..0108b6d --- /dev/null +++ b/.github/workflows/deployment.yml @@ -0,0 +1,79 @@ +name: 'Deployment' + +on: + push: + branches: + - main + - master + - develop + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Setup Pakman + uses: upmaru/pakman@v8 + with: + alpine: v3.19 + + - name: Bootstrap Configuration + run: | + pakman bootstrap + shell: alpine.sh {0} + env: + ABUILD_PRIVATE_KEY: ${{secrets.ABUILD_PRIVATE_KEY}} + ABUILD_PUBLIC_KEY: ${{secrets.ABUILD_PUBLIC_KEY}} + + - name: 'Build Package' + run: | + cd "$GITHUB_WORKSPACE"/.apk/"$GITHUB_REPOSITORY" || exit + + abuild snapshot + abuild -r + shell: alpine.sh {0} + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ runner.arch }} + path: /home/runner/packages + + deploy: + name: Deploy + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: actions/download-artifact@v3 + with: + path: /home/runner/artifacts + + - name: Setup Pakman + uses: upmaru/pakman@v8 + with: + alpine: v3.19 + + - name: Merge Artifact + run: | + cp -R /home/runner/artifacts/X64/. /home/runner/packages/ + sudo zip -r /home/runner/packages.zip "$HOME"/packages + shell: alpine.sh {0} + + - name: Push + run: pakman push + shell: alpine.sh {0} + env: + WORKFLOW_REF: ${{ github.ref }} + WORKFLOW_SHA: ${{ github.sha }} + INSTELLAR_ENDPOINT: https://opsmaru.com + INSTELLAR_PACKAGE_TOKEN: ${{secrets.INSTELLAR_PACKAGE_TOKEN}} + INSTELLAR_AUTH_TOKEN: ${{secrets.INSTELLAR_AUTH_TOKEN}} \ No newline at end of file diff --git a/instellar.yml b/instellar.yml new file mode 100644 index 0000000..4e058e0 --- /dev/null +++ b/instellar.yml @@ -0,0 +1,82 @@ +dependencies: + build: + - elixir + - npm + runtime: + - bash + - curl + - s6 + - jq + - ca-certificates + - polar-openrc + trace: true + +stack: alpine/3.19 + +build: + command: | + export MIX_ENV=prod + + mix local.hex --force + mix local.rebar --force + mix do deps.get --only prod + + # npm --prefix ./assets install ./assets + + # Comment out mix assets.deploy for non phoenix apps + mix assets.deploy + + mix release + destination: + - _build/prod/rel/polar/* + +run: + commands: + - binary: polar + call: eval 'Polar.Release.Tasks.migrate' + name: migrate + - binary: polar + call: remote + name: console + - binary: tail + call: -f -n 100 /var/log/polar/current + name: logs + path: /usr/bin + name: polar + services: + - binary: polar + name: web + start: + call: start + +hook: + post-deinstall: | + rc-service polar stop + rc-update del polar + post-install: | + rc-update add polar + rc-service polar migrate + post-upgrade: | + rc-service polar migrate + rc-service polar start + pre-upgrade: | + rc-service polar stop + +kits: + - description: Web service + main: true + name: web + ports: + - main: true + name: web + target: 4000 + variables: + - default_value: 'true' + key: PHX_SERVER + - driver: generic/secret + driver_options: + length: 128 + key: SECRET_KEY_BASE + - default_value: ecto:/// + driver: database/postgresql + key: DATABASE From 777707addedecb3e18f02b76f025ae12ef2c84fb Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Tue, 20 Feb 2024 11:49:04 +0700 Subject: [PATCH 2/4] Add release task --- lib/polar/release.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/polar/release.ex diff --git a/lib/polar/release.ex b/lib/polar/release.ex new file mode 100644 index 0000000..050fc00 --- /dev/null +++ b/lib/polar/release.ex @@ -0,0 +1,24 @@ +defmodule Polar.Release do + @app :polar + + def migrate do + load_app() + + for repo <- repos() do + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) + end + end + + def rollback(repo, version) do + load_app() + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) + end + + defp repos do + Application.fetch_env!(@app, :ecto_repos) + end + + defp load_app do + Application.load(@app) + end +end From 553d64db1b2c67283c5414bdc88e9ddb091ae060 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Tue, 20 Feb 2024 12:15:59 +0700 Subject: [PATCH 3/4] Change release task --- instellar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instellar.yml b/instellar.yml index 4e058e0..ad4d525 100644 --- a/instellar.yml +++ b/instellar.yml @@ -33,7 +33,7 @@ build: run: commands: - binary: polar - call: eval 'Polar.Release.Tasks.migrate' + call: eval 'Polar.Release.migrate' name: migrate - binary: polar call: remote From b1e0917c9dcaa8b5e7a383c235e5cd8cde8f80f9 Mon Sep 17 00:00:00 2001 From: Zack Siri Date: Tue, 20 Feb 2024 14:21:47 +0700 Subject: [PATCH 4/4] Add aws s3 bucket --- instellar.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instellar.yml b/instellar.yml index ad4d525..2f4e5f0 100644 --- a/instellar.yml +++ b/instellar.yml @@ -80,3 +80,5 @@ kits: - default_value: ecto:/// driver: database/postgresql key: DATABASE + - driver: bucket/aws-s3 + key: AWS_S3