Build Next app before packaging runtime image #56
This file contains hidden or 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: Build and Push Docker Images | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| docker: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm install --legacy-peer-deps | |
| - name: Build Next standalone output | |
| env: | |
| NEXT_TELEMETRY_DISABLED: '1' | |
| run: npm run build | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Resolve Docker Hub credentials | |
| id: dockerhub | |
| shell: bash | |
| env: | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} | |
| DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
| run: | | |
| username="${DOCKERHUB_USERNAME:-${DOCKERHUB_USER:-duanxiaosheng}}" | |
| password="${DOCKERHUB_TOKEN:-${DOCKER_HUB_TOKEN:-${DOCKERHUB_PASSWORD:-${DOCKER_PASSWORD:-}}}}" | |
| echo "username=$username" >> "$GITHUB_OUTPUT" | |
| if [ -z "$password" ]; then | |
| echo "::error::Missing Docker Hub password/token secret. Set one of: DOCKERHUB_TOKEN, DOCKER_HUB_TOKEN, DOCKERHUB_PASSWORD, DOCKER_PASSWORD" | |
| exit 1 | |
| fi | |
| echo "password=$password" >> "$GITHUB_OUTPUT" | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ steps.dockerhub.outputs.username }} | |
| password: ${{ steps.dockerhub.outputs.password }} | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ghcr.io/duanxiaosheng/2025-blog-public-docker | |
| duanxiaosheng/2025-blog-local-docker | |
| tags: | | |
| type=raw,value=latest | |
| type=sha | |
| type=ref,event=branch | |
| - name: Build and push runtime image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile.release | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} |