added publish file #1
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: Application Build & Publish | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| # Set the image name to be the GitHub repository, which is 'owner/repo-name'. | |
| # For GHCR, the image will be ghcr.io/owner/repo-name. | |
| # For Docker Hub, you might want something like 'username/repo-name'. | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| # This permission is required to push to GitHub Packages (GHCR). | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| 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 | |
| - name: Build application | |
| run: npm run build | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # The user's example used secrets.DOCKER_HUB_TOKEN, which implies Docker Hub. | |
| # However, the 'packages: write' permission is for GHCR. | |
| # This workflow uses GHCR by default as it is more integrated. | |
| # To use Docker Hub, uncomment the Docker Hub login, comment out the GHCR login, | |
| # and ensure your IMAGE_NAME is correct for Docker Hub (e.g., your-username/repo-name). | |
| # You will also need to set DOCKER_HUB_TOKEN and DOCKER_HUB_USERNAME secrets in your repository. | |
| # - name: Log into Docker Hub | |
| # if: github.event_name != 'pull_request' | |
| # uses: docker/login-action@v3 | |
| # with: | |
| # username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
| # password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
| - name: Log into GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| # For GHCR, the image name is ghcr.io/owner/repo-name. | |
| # For Docker Hub, it would be username/repo-name. | |
| images: ghcr.io/${{ env.IMAGE_NAME }} | |
| # To use Docker Hub, change to: | |
| # images: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }} | |
| - name: Build and push Docker image | |
| id: build-and-push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |