Skip to content

Commit

Permalink
improvement: deploy fly app after image test and reuse ghcr image
Browse files Browse the repository at this point in the history
  • Loading branch information
cao7113 committed Jul 13, 2024
1 parent ee09694 commit 4980aa2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Elixir CI
on:
# push:
# branches: ["main"]
# branches:
# - main
pull_request:
branches: ["main"]
branches:
- main

workflow_call:

Expand Down
64 changes: 28 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,6 @@ jobs:
name: Check CI
uses: ./.github/workflows/ci.yml

# direct use ghcr or docker-hub image?
fly-deploy:
name: Deploy fly app
runs-on: ubuntu-latest
needs: check-ci
concurrency: deploy-group
steps:
- name: Checkout code
uses: actions/checkout@v4

# https://github.com/superfly/flyctl-actions
# https://github.com/marketplace/actions/github-action-for-flyctl
- name: Setup flyctl
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Deploy app
run: flyctl deploy --remote-only --build-arg GIT_COMMIT_ID=$(git log -1 --format="%H") --build-arg GIT_COMMIT_TIME=$(git log -1 --format="%ct")
env:
# https://github.com/superfly/flyctl-actions?tab=readme-ov-file#secrets
# https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/#speed-run-your-way-to-continuous-deployment
# gen cmd: fly tokens create deploy -x 999999h
# set in Github Settings -> Secrets -> Actions -> Repository secrets
# https://github.com/cao7113/hello-phx/settings/secrets/actions
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

push-images:
name: Push Docker image to Docker Hub and Github Packages
runs-on: ubuntu-latest
Expand All @@ -58,10 +33,10 @@ jobs:
run: |
echo GIT_COMMIT_TIME=$(git log -1 --format="%ct") >> $GITHUB_ENV
echo GIT_COMMIT_ID=$(git log -1 --format="%H") >> $GITHUB_ENV
- name: Inspect Commit Env
run: |
echo GIT_COMMIT_ID=$GIT_COMMIT_ID vs ${{ env.GIT_COMMIT_ID }} in env context
echo GIT_COMMIT_TIME=$GIT_COMMIT_TIME vs ${{ env.GIT_COMMIT_TIME }} in env context
# - name: Inspect Commit Env
# run: |
# echo GIT_COMMIT_ID=$GIT_COMMIT_ID vs ${{ env.GIT_COMMIT_ID }} in env context
# echo GIT_COMMIT_TIME=$GIT_COMMIT_TIME vs ${{ env.GIT_COMMIT_TIME }} in env context

# https://github.com/docker/login-action
- name: Log in to Docker Hub
Expand Down Expand Up @@ -97,7 +72,6 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# https://github.com/docker/build-push-action?tab=readme-ov-file#customizing
# GIT_COMMIT_TIME=$(git log -1 --format="%ct")
build-args: |
GIT_COMMIT_ID=${{ github.sha }}
GIT_COMMIT_TIME=${{ env.GIT_COMMIT_TIME }}
Expand All @@ -115,13 +89,31 @@ jobs:
needs: push-images
uses: ./.github/workflows/docker.yml

fly-deploy:
name: Deploy fly app
runs-on: ubuntu-latest
needs: test-docker-images
concurrency: deploy-group
steps:
- name: Checkout code
uses: actions/checkout@v4

# https://github.com/superfly/flyctl-actions
# https://github.com/marketplace/actions/github-action-for-flyctl
- name: Setup flyctl
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Deploy fly app
run: fly deploy --image ghcr.io/cao7113/hello-phx:{{ github.ref_name }} --debug --verbose
env:
# https://github.com/superfly/flyctl-actions?tab=readme-ov-file#secrets
# https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/#speed-run-your-way-to-continuous-deployment
# https://github.com/cao7113/hello-phx/settings/secrets/actions
# gen cmd: fly tokens create deploy -x 999999h
# set in Github Settings -> Secrets -> Actions -> Repository secrets
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

release-tar:
# strategy:
# matrix:
# # erlef/setup-beam only supports Ubuntu and Windows at this time
# os: [ubuntu-latest]
# otp: [27.x]
# elixir: [1.17.x]
name: Publish mix release tar
runs-on: ubuntu-latest
needs: check-ci
Expand Down
2 changes: 2 additions & 0 deletions Taskfile-fly-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ tasks:
st: fly status
# deploy new app version
up: fly deploy --build-arg GIT_COMMIT_ID=$(git log -1 --format="%H") --build-arg GIT_COMMIT_TIME=$(git log -1 --format="%ct")
# task f:upv -- v0.1.6
upv: fly deploy --image ghcr.io/cao7113/hello-phx:{{.CLI_ARGS}} --debug --verbose
reup: fly app restart
log: fly logs
open: fly open
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ services:
# ping -c 3 web
echo Ping web api
curl -sS http://web:4000/api/ping
echo
echo Get web build info
curl -sS http://web:4000/api
echo
Expand Down

0 comments on commit 4980aa2

Please sign in to comment.