Skip to content

Commit defd0f6

Browse files
committed
Add GitHub Actions workflow for building and pushing Docker images
1 parent 5a429e1 commit defd0f6

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Build and Push Docker Images
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ main, master ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- dockerfile: Dockerfile
23+
image: ghcr.io/${{ github.repository }}
24+
# - dockerfile: frontend/.docker/Dockerfile
25+
# image: ghcr.io/${{ github.repository }}/frontend
26+
# context: frontend
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Login to GitHub Container Registry
36+
uses: docker/login-action@v3
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.actor }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Extract metadata for Docker
43+
id: meta
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ matrix.image }}
47+
tags: |
48+
type=ref,event=branch
49+
type=ref,event=pr
50+
type=semver,pattern={{version}}
51+
type=sha,format=short
52+
53+
- name: Build and push Docker image
54+
uses: docker/build-push-action@v5
55+
with:
56+
context: ${{ matrix.context }}
57+
file: ${{ matrix.dockerfile }}
58+
push: ${{ github.event_name != 'pull_request' }}
59+
tags: ${{ steps.meta.outputs.tags }}
60+
labels: ${{ steps.meta.outputs.labels }}
61+
cache-from: type=gha
62+
cache-to: type=gha,mode=max
63+
build-args: |
64+
BUILD_TIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
65+
BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
66+
BUILD_REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
67+

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM node:22-bookworm as build-env
2+
3+
WORKDIR /app
4+
5+
COPY package.json /app
6+
COPY package-lock.json /app
7+
8+
RUN --mount=type=cache,sharing=shared,id=npm_cache,target=/root/.npm npm install
9+
10+
COPY . .
11+
12+
ARG BUILD_TIME
13+
ARG BUILD_VERSION
14+
ARG BUILD_REVISION
15+
16+
#RUN sed -i -e "s#__DEV_DIRTY__#${BUILD_VERSION}-${BUILD_REVISION}#g" src/main.js
17+
18+
CMD ["/nodejs/bin/node", "--enable-source-maps", "/app/tuya-mqtt.js"]
19+
20+
21+
#FROM gcr.io/distroless/nodejs22-debian12
22+
#
23+
#COPY --from=busybox:1.35.0-uclibc /bin/sh /bin/sh
24+
#COPY --from=busybox:1.35.0-uclibc /bin/tar /bin/tar
25+
#
26+
#COPY --from=build-env /app/dist /app
27+
#COPY --from=build-env /app/node_modules /app/node_modules
28+
#
29+
#ENTRYPOINT []
30+
#
31+
32+

0 commit comments

Comments
 (0)