Skip to content

Commit bbe6ae9

Browse files
committed
Update Add Build Coding, File
1 parent a1cd1cc commit bbe6ae9

File tree

5 files changed

+236
-1
lines changed

5 files changed

+236
-1
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build & Push coding-service
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- "coding-service/**"
8+
- "docker/java-service-coding.Dockerfile"
9+
- ".github/workflows/coding-service-publish.yml"
10+
tags:
11+
- "v*.*.*"
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
concurrency:
19+
group: docker-coding-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
build-push:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Set up QEMU (multi-arch)
31+
uses: docker/setup-qemu-action@v3
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Derive IMAGE_TAG
37+
run: |
38+
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
39+
echo "IMAGE_TAG=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
40+
else
41+
echo "IMAGE_TAG=${GITHUB_SHA::12}" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Login to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKERHUB_USER }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: Build & Push coding-service
51+
env:
52+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
53+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
54+
IMAGE_TAG: ${{ env.IMAGE_TAG }}
55+
DOCKER_PLATFORMS: linux/amd64
56+
run: |
57+
chmod +x ./build-image-coding-github.sh
58+
./build-image-coding-github.sh coding-service

.github/workflows/docker-publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ jobs:
2424
- identity-service
2525
- submission-service
2626
- quiz-service
27-
- coding-service
2827
- ai-service
2928
- search-service
3029
- notification-service
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build & Push file-service
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- "FileService/**"
8+
- "docker/file-service.Dockerfile"
9+
- ".github/workflows/file-service-publish.yml"
10+
tags:
11+
- "v*.*.*"
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
concurrency:
19+
group: docker-file-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
build-push:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
30+
- name: Set up QEMU (multi-arch)
31+
uses: docker/setup-qemu-action@v3
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Derive IMAGE_TAG
37+
run: |
38+
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
39+
echo "IMAGE_TAG=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
40+
else
41+
echo "IMAGE_TAG=${GITHUB_SHA::12}" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Login to Docker Hub
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ secrets.DOCKERHUB_USER }}
48+
password: ${{ secrets.DOCKERHUB_TOKEN }}
49+
50+
- name: Build & Push file-service
51+
env:
52+
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
53+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
54+
IMAGE_TAG: ${{ env.IMAGE_TAG }}
55+
DOCKER_PLATFORMS: linux/amd64
56+
run: |
57+
chmod +x ./build-image-file.sh
58+
./build-image-file.sh

build-image-coding-github.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
export DOCKER_BUILDKIT=1
4+
5+
DOCKERHUB_USER="${DOCKERHUB_USER:-yunomix2834}"
6+
DOCKERHUB_TOKEN="${DOCKERHUB_TOKEN:-}"
7+
IMAGE_TAG="${IMAGE_TAG:-$(date +%Y%m%d.%H%M%S)}"
8+
DOCKER_PLATFORMS="${DOCKER_PLATFORMS:-linux/amd64}"
9+
10+
# Xác định DOCKER_GID an toàn
11+
if [[ "${OSTYPE:-}" == "darwin"* ]]; then
12+
DOCKER_GID=999
13+
elif [ -S /var/run/docker.sock ]; then
14+
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock 2>/dev/null || echo 999)
15+
else
16+
DOCKER_GID=999
17+
fi
18+
19+
log() { echo "[$(date +'%H:%M:%S')] $*"; }
20+
21+
login() {
22+
if [ -n "$DOCKERHUB_TOKEN" ]; then
23+
log "Logging in Docker Hub as $DOCKERHUB_USER"
24+
echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
25+
else
26+
log "DOCKERHUB_TOKEN empty -> skip docker login (build will fail on --push if registry requires auth)"
27+
fi
28+
}
29+
30+
extra_tags_args() {
31+
local repo="$1"
32+
local args=()
33+
if [ "${GITHUB_REF_TYPE:-}" = "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
34+
local version="${GITHUB_REF_NAME#v}"
35+
args+=(-t "${repo}:${version}")
36+
fi
37+
if [ "${GITHUB_REF_NAME:-}" = "main" ]; then
38+
args+=(-t "${repo}:latest")
39+
fi
40+
printf '%s ' "${args[@]}"
41+
}
42+
43+
build_push_coding() {
44+
local module="${1:-coding-service}"
45+
local repo="${DOCKERHUB_USER}/codecampus-${module}"
46+
47+
log "Building coding-service with DOCKER_GID=${DOCKER_GID}"
48+
docker buildx build \
49+
--platform "${DOCKER_PLATFORMS}" \
50+
-f docker/java-service-coding.Dockerfile \
51+
--build-arg "MODULE=${module}" \
52+
--build-arg "DOCKER_HOST_GID=${DOCKER_GID}" \
53+
-t "${repo}:${IMAGE_TAG}" \
54+
$(extra_tags_args "${repo}") \
55+
--label "org.opencontainers.image.source=${GITHUB_SERVER_URL:-}/$([ -n "${GITHUB_REPOSITORY:-}" ] && echo "${GITHUB_REPOSITORY}")" \
56+
--label "org.opencontainers.image.revision=${GITHUB_SHA:-}" \
57+
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
58+
--push .
59+
}
60+
61+
main() {
62+
login
63+
build_push_coding "${1:-coding-service}"
64+
log "Done."
65+
}
66+
67+
main "$@"

build-image-file.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
export DOCKER_BUILDKIT=1
4+
5+
DOCKERHUB_USER="${DOCKERHUB_USER:-yunomix2834}"
6+
DOCKERHUB_TOKEN="${DOCKERHUB_TOKEN:-}"
7+
IMAGE_TAG="${IMAGE_TAG:-$(date +%Y%m%d.%H%M%S)}"
8+
DOCKER_PLATFORMS="${DOCKER_PLATFORMS:-linux/amd64}"
9+
10+
log() { echo "[$(date +'%H:%M:%S')] $*"; }
11+
12+
login() {
13+
if [ -n "$DOCKERHUB_TOKEN" ]; then
14+
log "Logging in Docker Hub as $DOCKERHUB_USER"
15+
echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
16+
else
17+
log "DOCKERHUB_TOKEN empty -> skip docker login (build will fail on --push if registry requires auth)"
18+
fi
19+
}
20+
21+
extra_tags_args() {
22+
local repo="$1"
23+
local args=()
24+
if [ "${GITHUB_REF_TYPE:-}" = "tag" ] && [ -n "${GITHUB_REF_NAME:-}" ]; then
25+
local version="${GITHUB_REF_NAME#v}"
26+
args+=(-t "${repo}:${version}")
27+
fi
28+
if [ "${GITHUB_REF_NAME:-}" = "main" ]; then
29+
args+=(-t "${repo}:latest")
30+
fi
31+
printf '%s ' "${args[@]}"
32+
}
33+
34+
build_push_file_service() {
35+
local repo="${DOCKERHUB_USER}/codecampus-file-service"
36+
docker buildx build \
37+
--platform "${DOCKER_PLATFORMS}" \
38+
-f docker/file-service.Dockerfile \
39+
-t "${repo}:${IMAGE_TAG}" \
40+
$(extra_tags_args "${repo}") \
41+
--label "org.opencontainers.image.source=${GITHUB_SERVER_URL:-}/$([ -n "${GITHUB_REPOSITORY:-}" ] && echo "${GITHUB_REPOSITORY}")" \
42+
--label "org.opencontainers.image.revision=${GITHUB_SHA:-}" \
43+
--label "org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
44+
--push .
45+
}
46+
47+
main() {
48+
login
49+
build_push_file_service
50+
log "Done."
51+
}
52+
53+
main "$@"

0 commit comments

Comments
 (0)