Skip to content

Commit b4f1e9f

Browse files
committed
Put building and publishing docker image into its own workflow
1 parent d342e7c commit b4f1e9f

File tree

2 files changed

+70
-21
lines changed

2 files changed

+70
-21
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Node.js CI - Dockge
22

3-
env:
4-
IMAGE_NAME: Dockge
5-
63
on:
74
push:
85
branches: [master]
@@ -62,22 +59,5 @@ jobs:
6259

6360
- name: Build
6461
run: pnpm run build:frontend
65-
66-
- name: Build image
67-
run: docker build . --file docker/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
68-
69-
- name: Log in to registry
70-
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
71-
72-
- name: Push image
73-
run: |
74-
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
75-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
76-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
77-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
78-
[ "$VERSION" == "main" ] && VERSION=latest
79-
echo IMAGE_ID=$IMAGE_ID
80-
echo VERSION=$VERSION
81-
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
82-
docker push $IMAGE_ID:$VERSION
62+
# more things can be add later like tests etc..
8363

.github/workflows/publish.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Publish to ghcr.io
2+
3+
env:
4+
IMAGE_NAME: Dockge
5+
6+
on:
7+
push:
8+
tags: [.+]
9+
paths-ignore:
10+
- '*.md'
11+
12+
jobs:
13+
build-and-publish-image:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 22
23+
24+
- uses: pnpm/action-setup@v2
25+
name: Install pnpm
26+
with:
27+
version: 8
28+
run_install: false
29+
30+
- name: Get pnpm store directory
31+
shell: bash
32+
run: |
33+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
34+
35+
- uses: actions/cache@v3
36+
name: Setup pnpm cache
37+
with:
38+
path: ${{ env.STORE_PATH }}
39+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
40+
restore-keys: |
41+
${{ runner.os }}-pnpm-store-
42+
43+
- name: Install dependencies
44+
run: pnpm install
45+
46+
- name: Lint
47+
run: pnpm run lint
48+
49+
- name: Check Typescript
50+
run: pnpm run check-ts
51+
52+
- name: Build Docker image
53+
run: docker build . --file docker/Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
54+
55+
- name: Log in to registry
56+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
57+
58+
- name: Push image
59+
run: |
60+
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
61+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
62+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
63+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
64+
[ "$VERSION" == "main" ] && VERSION=latest
65+
echo IMAGE_ID=$IMAGE_ID
66+
echo VERSION=$VERSION
67+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
68+
docker push $IMAGE_ID:$VERSION
69+

0 commit comments

Comments
 (0)