feat: [功能開發] 註冊會員 api 串接 #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CICD | |
on: | |
push: | |
branches: [ "docker-compose-InBackend" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Set up Docker Buildx for production | |
uses: docker/setup-buildx-action@v3 | |
id: production_builder | |
- | |
name: Set up Docker Buildx for test | |
uses: docker/setup-buildx-action@v3 | |
id: test_builder | |
- | |
name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- | |
name: Build and push test image | |
uses: docker/build-push-action@v5 | |
with: | |
builder: ${{ steps.test_builder.outputs.name }} | |
context: . | |
file: ./Dockerfile.backend | |
push: true | |
target: base | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/incan_gold_test:latest | |
cache-from: type=local,src=/tmp/.buildx-cache | |
- | |
name: Build and push production image | |
uses: docker/build-push-action@v5 | |
with: | |
builder: ${{ steps.production_builder.outputs.name }} | |
context: . | |
file: ./Dockerfile.backend | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/incan_gold:latest | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
- | |
name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
environment: TEST | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
uses: isbang/[email protected] | |
with: | |
compose-file: "./docker-compose.test.yml" | |
env: | |
PORT: ${{ vars.PORT }} | |
DB_USERNAME: ${{ vars.DB_USERNAME }} | |
DB_PASSWORD: ${{ vars.DB_PASSWORD }} | |
DB_NAME: ${{ vars.DB_NAME }} | |
JWT_SECRET: ${{ vars.JWT_SECRET }} | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
deploy: | |
name: Deploy to Fly.io | |
runs-on: ubuntu-latest | |
needs: [build, test] | |
environment: PRODUCTION | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Setup Flyctl | |
uses: superfly/flyctl-actions/setup-flyctl@master | |
- | |
name: Replace env variables | |
run: | | |
sed -i "s/{{PORT}}/$PORT/g" fly.toml | |
sed -i "s/{{DB_PORT}}/$DB_PORT/g" fly.toml | |
sed -i "s/{{DB_HOST}}/$DB_HOST/g" fly.toml | |
sed -i "s/{{DB_USERNAME}}/$DB_USERNAME/g" fly.toml | |
sed -i "s/{{DB_NAME}}/$DB_NAME/g" fly.toml | |
sed -i "s/{{DOCKERHUB_USERNAME}}/$DOCKERHUB_USERNAME/g" fly.toml | |
env: | |
PORT: ${{vars.PORT}} | |
DB_PORT: ${{vars.DB_PORT}} | |
DB_HOST: ${{vars.DB_HOST}} | |
DB_USERNAME: ${{vars.DB_USERNAME}} | |
DB_NAME: ${{vars.DB_NAME}} | |
DOCKERHUB_USERNAME: ${{secrets.DOCKERHUB_USERNAME}} | |
- | |
name: Deploy to Fly.io | |
run: flyctl deploy | |
env: | |
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} |