diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f072fb6 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,93 @@ +name: ci + +on: + push: + workflow_dispatch: + inputs: + tag: + description: 'Tag to deploy' + required: false + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Cache Poetry dependencies + uses: actions/cache@v4 + with: + path: | + ~/.cache/pypoetry + ~/.cache/pip + key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} + restore-keys: | + ${{ runner.os }}-poetry- + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + pip install poetry + poetry sync + + - name: Run tests + run: | + poetry run python -m unittest + + docker: + runs-on: ubuntu-latest + needs: [run-tests] + if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'develop') + permissions: + contents: read + packages: write # required to push to ghcr.io + id-token: write # optional for OIDC if you use it + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Prepare image tags + run: | + OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]') + REPO=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]') + + # Determine tag + if [ "${GITHUB_REF_NAME}" = "main" ]; then + TAG="latest" + else + TAG="dev" + fi + + SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7) + IMAGE_BASE="ghcr.io/${OWNER}/${REPO}" + + echo "IMAGE_LATEST=${IMAGE_BASE}:${TAG}" >> $GITHUB_ENV + echo "IMAGE_SHA=${IMAGE_BASE}:sha-${SHORT_SHA}" >> $GITHUB_ENV + + - name: Build and push Docker image (with registry cache) + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: | + ${{ env.IMAGE_LATEST }} + ${{ env.IMAGE_SHA }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index e3afef4..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: ci - -on: - push: - branches: - - 'main' - -jobs: - - docker: - - runs-on: ubuntu-latest - steps: - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - platforms: linux/amd64,linux/arm64 - push: true - tags: yoshiunfriendly/storage-hideyoshi.com:latest - - run-dispatcher: - needs: docker - runs-on: ubuntu-latest - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - name: Runs Infra-Hideyoshi.com Deployment Dispatcher - run: | - curl -X POST https://api.github.com/repos/HideyoshiSolutions/infra-hideyoshi.com/dispatches \ - -H 'Accept: application/vnd.github.everest-preview+json' \ - -u ${{ secrets.ACTIONS_KEY }} \ - --data '{"event_type": "refresh-deployments", "client_payload": { "deployments": "storage-deployment storage-processor-deployment" }}' \ No newline at end of file diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml deleted file mode 100644 index 37169e1..0000000 --- a/.github/workflows/run-tests.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: ci - -on: - push - -jobs: - - run-tests: - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install poetry - poetry install - - - name: Run tests - run: | - poetry run python -m unittest \ No newline at end of file