Skip to content

Commit dac5a65

Browse files
committed
feat: add push image action
add push image action add push image action
1 parent 417299d commit dac5a65

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/image.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Image build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- v*
9+
pull_request:
10+
11+
env:
12+
IMAGE_NAME: web-app
13+
MONGO_DB_ADMIN_PASSWD: ${{ secrets.MONGO_DB_ADMIN_PASSWD }}
14+
MONGO_DB_ADMIN_USER: ${{ secrets.MONGO_DB_ADMIN_USER }}
15+
16+
jobs:
17+
18+
push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
package: write
22+
contents: read
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Build image
27+
run: docker compose build app
28+
- name: Tag with Image
29+
run: docker tag web-app:latest $IMAGE_NAME:$GITHUB_SHA
30+
- name: Log in to registry
31+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
32+
- name: Push to registry
33+
run: |
34+
IMAGE_ID=ghcr.io/leetcode-golang-classroom/$IMAGE_NAME
35+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
36+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
37+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
38+
[ "$VERSION" == "main" ] && VERSION=latest
39+
echo IMAGE_ID=$IMAGE_ID
40+
echo VERSION=$VERSION
41+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
42+
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)