-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (68 loc) · 2.66 KB
/
Copy pathmain-build-publish.yml
File metadata and controls
81 lines (68 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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