1+ name : Build and Push Multi-Arch Docker Image
2+
3+ on :
4+ push :
5+ branches : [feature/cicd/generate-docker-image ]
6+ tags : [ 'v*' ]
7+ workflow_dispatch :
8+
9+ jobs :
10+ build :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ # Checkout source
15+ - name : Checkout repository
16+ uses : actions/checkout@v4
17+
18+ # Get version from tag or fallback to short SHA
19+ - name : Extract version
20+ id : vars
21+ run : |
22+ if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
23+ VERSION=${GITHUB_REF_NAME}
24+ else
25+ VERSION=$(echo "${GITHUB_SHA}" | cut -c1-7)
26+ fi
27+ echo "version=$VERSION" >> $GITHUB_OUTPUT
28+
29+ # Generate package.json dynamically
30+ - name : Generate package.json
31+ run : |
32+ echo "{
33+ \"name\": \"@evershop/evershop\",
34+ \"version\": \"${{ steps.vars.outputs.version }}\",
35+ \"dependencies\": {
36+ \"@evershop/evershop\": \"${{ steps.vars.outputs.version }}\"
37+ },
38+ \"devDependencies\": {
39+ \"esbuild\": \"^0.20.1\",
40+ \"tsx\": \"^4.19.3\",
41+ \"typescript\": \"^5.8.3\"
42+ },
43+ \"type\": \"module\",
44+ \"scripts\": {
45+ \"start\": \"evershop start\",
46+ \"build\": \"evershop build\",
47+ \"setup\": \"evershop install\",
48+ \"seed\": \"evershop seed\",
49+ \"user:create\": \"evershop user:create\",
50+ \"user:changePassword\": \"evershop user:changePassword\"
51+ }
52+ }" > package.json
53+
54+ # Log in to Docker Hub
55+ - name : Log in to Docker Hub
56+ uses : docker/login-action@v3
57+ with :
58+ username : ${{ secrets.DOCKERHUB_USERNAME }}
59+ password : ${{ secrets.DOCKERHUB_TOKEN }}
60+
61+ # Set up Docker Buildx for multi-platform build
62+ - name : Set up Docker Buildx
63+ uses : docker/setup-buildx-action@v3
64+
65+ # Build and push multi-platform image
66+ - name : Build and push Docker image
67+ uses : docker/build-push-action@v6
68+ with :
69+ context : .
70+ file : ./Dockerfile
71+ platforms : linux/amd64,linux/arm64
72+ push : true
73+ tags : |
74+ ${{ secrets.DOCKERHUB_USERNAME }}/evershop:latest
75+ ${{ secrets.DOCKERHUB_USERNAME }}/evershop:${{ steps.vars.outputs.version }}
0 commit comments