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 dd7b868 commit d696811
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 83 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
34 changes: 5 additions & 29 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,10 @@ jobs:
test-docker:
runs-on: ubuntu-latest
services:
api-server:
image: cao7113/hello-api-elixir
ports:
- 4000:4000
- name: Checkout code
uses: actions/checkout@v4

# https://github.com/cao7113/hello-api-elixir/pkgs/container/hello-api-elixir
# Fix: "unsupported media type application/vnd.oci.empty.v1+json"
# use ghcr.io/cao7113/hello-api-elixir:v0.1.8 instead of ghcr.io/cao7113/hello-api-elixir:sha256-b3de0aa2c4d72189aeb6e36fe8377400e1f9e6f4fbc60270b3e05b2e3350462b
api-server2:
image: ghcr.io/cao7113/hello-api-elixir
ports:
- 4002:4000

steps:
# - name: Checkout code
# uses: actions/checkout@v4

- name: Ping api-server
run: |
sleep 1
echo Ping api-server
curl -sSL http://localhost:4000/ping
echo Ping api-server2
curl -sSL http://localhost:4002/ping
- name: Api build info
- name: Run app in docker compose env
run: |
echo api-server build info:
curl -sSL http://localhost:4000 | jq
echo api-server2 build info:
curl -sSL http://localhost:4002 | jq
docker compose version
docker compose up --exit-code-from curl # --abort-on-container-exit
50 changes: 25 additions & 25 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-api-elixir/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 Down Expand Up @@ -115,6 +90,31 @@ jobs:
needs: push-images
uses: ./.github/workflows/docker.yml

# direct use ghcr or docker-hub image?
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: flyctl deploy --image ghcr.io/${{ github.repository }}:${{ 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:
Expand Down
51 changes: 24 additions & 27 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
services:
# https://github.com/cao7113/hello-phx/pkgs/container/hello-api-elixir
api:
# image: ghcr.io/cao7113/hello-api-elixir
build: .
image: ghcr.io/cao7113/hello-api-elixir
# build: .
# environment:
# MIX_ENV: "prod"
# https://docs.docker.com/compose/compose-file/05-services/#healthcheck
Expand All @@ -12,41 +12,38 @@ services:
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
start_period: 30s
start_interval: 5s

# http://hello-api-elixir-api-1.orb.local/

curl:
image: curlimages/curl:8.8.0
depends_on:
- api
api:
condition: service_healthy
command: >
sh -c "
sleep 2
echo ping api
curl http://api/ping
# echo
# ping -c 3 api
echo
echo ping api at port 4000
curl http://api:4000/ping
echo ping api
curl -sSL http://api:4000/ping
echo
ping -c 3 api
ping -q api
echo get build info
curl -sSL http://api:4000/
"
tool:
image: busybox
depends_on:
- api
command: >
sh -c "
sleep 2
echo ping api
wget -qO- http://api/ping
echo
echo ping api at port 4000
wget -qO- http://api:4000/ping
echo
ping -c 3 api
ping -q api
"
# tool:
# image: busybox
# depends_on:
# api:
# condition: service_healthy
# command: >
# sh -c "
# # echo
# # ping -c 3 api
# echo
# echo ping api at port 4000
# wget -qO- http://api:4000/ping
# "

0 comments on commit d696811

Please sign in to comment.