Skip to content

chore: release version v0.1.19 #15

chore: release version v0.1.19

chore: release version v0.1.19 #15

Workflow file for this run

name: Release Deployment
on:
push:
tags:
- "v*"
permissions:
contents: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
check-ci:
name: Check CI
uses: ./.github/workflows/ci.yml
push-images:
name: Push Docker image to Docker Hub and Github Packages
runs-on: ubuntu-latest
needs: check-ci
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set Commit Env from git command
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
# https://github.com/docker/login-action
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# https://github.com/docker/metadata-action
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
cao7113/hello-api-elixir
ghcr.io/${{ github.repository }}
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
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 }}
# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-docker-hub
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
test-docker-images:
name: Test latest docker images
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:
# # 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
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- name: Restore dependencies cache
uses: actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get --only prod
- name: Make mix release
run: |
export GIT_COMMIT_ID=${{ github.sha }}
# export GIT_COMMIT_ID=$(git log -1 --format="%H")
export GIT_COMMIT_TIME=$(git log -1 --format="%ct")
MIX_ENV=prod RELEASE_TAR=1 mix release
# https://github.com/softprops/action-gh-release
- name: Make Github release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
# todo: add runner.os & runner.arch info in final tar filename
with:
files: _build/prod/*.tar.gz
# ssh-deploy:
# name: Deoloy to remote server by ssh
# runs-on: ubuntu-latest
# needs: release-tar
# steps:
# # https://github.com/appleboy/ssh-action
# # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# - name: executing remote ssh commands
# uses: appleboy/[email protected]
# with:
# host: ${{ secrets.REMOTE_HOST }}
# username: ${{ secrets.REMOTE_USERNAME }}
# key: ${{ secrets.REMOTE_PRIVKEY }}
# port: 22
# script: |
# vsn=${{ github.ref_name }}
# git_repo=${{ github.repository }}
# app_root=~/hello-api-elixir
# script_path=${app_root}/deploy.sh
# mkdir -p $app_root
# script_url="https://raw.githubusercontent.com/${git_repo}/main/run/deploy.sh"
# if [ ! -e $script_path ]; then
# wget -q -O $script_path $script_url
# chmod +x $script_path
# echo "Setup deploy-script into ${script_path} from ${script_url}"
# else
# echo "Use existed deploy-script: ${script_path}, manually delete it when need update"
# fi
# $script_path $vsn bin/hello_api ${git_repo} 3