Skip to content

Commit 80a70ae

Browse files
author
VuXfi
committed
add dockerfile
1 parent 4d1b302 commit 80a70ae

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

.github/workflows/demo.yml

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
name: Publish Package to npmjs
1+
name: Publish Docker Image to GHCR
2+
23
on:
34
push:
45
branches:
56
- next
7+
68
jobs:
7-
build:
9+
publish:
810
runs-on: ubuntu-latest
11+
permissions:
12+
packages: write
13+
contents: read
14+
915
steps:
1016
- uses: actions/checkout@v3
11-
# Setup .npmrc file to publish to npm
12-
- uses: actions/setup-node@v3
13-
with:
14-
node-version: '22.x'
15-
registry-url: 'https://registry.npmjs.org'
1617

17-
- run: npm i --force && npm run build
18-
- run: cp ./package.json ./dist && cp ./Readme.md ./dist/ && echo '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' > ./dist/.npmrc
18+
- name: Log in to GitHub Container Registry
19+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
20+
21+
- name: Set up image name
22+
id: meta
23+
run: |
24+
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/$(basename ${{ github.repository }} | tr '[:upper:]' '[:lower:]')
25+
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
26+
27+
- name: Build Docker image
28+
run: |
29+
docker build -f fixture/Dockerfile.demo -t ${{ steps.meta.outputs.image_name }}:demo .
1930
20-
# resolve version
21-
- run: |
22-
set -x
23-
BRANCH=${GITHUB_REF##*/}
24-
PACKAGE=$(cat package.json | jq -r '.["name"]')
25-
VERLOC=$(cat package.json | jq -r '.["version"]')
26-
VERNPMRAW=$(curl -s https://registry.npmjs.org/$PACKAGE | jq -r '.["dist-tags"].'$BRANCH'')
27-
BUILD_VERSION=0
28-
if [[ "$VERNPMRAW" == "null" ]]; then
29-
VEROUT=$VERLOC
30-
else
31-
VERNPM=$(echo $VERNPMRAW | cut -d'-' -f1)
32-
BUILD_VERSION=$(echo $VERNPMRAW | awk -F '[.-]' '{print $5+1}')
33-
VEROUT=$(printf "$VERNPM\n$VERLOC\n" | sort -V -r | awk 'NR==1 {print; exit}')
34-
fi
35-
jq -r '.version = "'${VEROUT}'-build.'$BUILD_VERSION'"' package.json > /tmp/package.json && mv /tmp/package.json ./package.json
36-
working-directory: ./dist
37-
38-
- run: npm publish --tag next
39-
env:
40-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41-
working-directory: ./dist
31+
- name: Push Docker image
32+
run: |
33+
docker push ${{ steps.meta.outputs.image_name }}:demo

fixture/Dockerfile.demo

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM node:20
2+
WORKDIR /app
3+
COPY package*.json ./
4+
RUN npm install
5+
COPY . .
6+
RUN npm run demo:build
7+
EXPOSE 3000
8+
CMD ["npm", "run", "demo"]

0 commit comments

Comments
 (0)