Update and Push Docker Image on New Code-Server Release #218
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update and Push Docker Image on New Code-Server Release | |
on: | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 0 */1 * *" # 每天執行一次 | |
jobs: | |
build-and-push: | |
runs-on: self-hosted | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Get the latest code-server release tag | |
id: latest_release | |
run: | | |
LATEST_RELEASE_TAG=$(curl -s https://api.github.com/repos/coder/code-server/releases/latest | jq -r '.tag_name') | |
LATEST_RELEASE_TAG=${LATEST_RELEASE_TAG#v} # 移除前綴 v | |
echo "LATEST_RELEASE_TAG=$LATEST_RELEASE_TAG" | |
echo "tag=$LATEST_RELEASE_TAG" >> $GITHUB_OUTPUT | |
# - name: Check if new release is available | |
# id: check_new_release | |
# env: | |
# PREVIOUS_RELEASE_TAG: ${{ secrets.PREVIOUS_RELEASE_TAG }} # 假設您將上一個版本存儲在了 Secrets 中 | |
# run: | | |
# if [[ "${{ steps.latest_release.outputs.tag }}" != "$PREVIOUS_RELEASE_TAG" ]]; then | |
# echo "NEW_RELEASE_FOUND=true" >> $GITHUB_ENV | |
# echo "${{ steps.latest_release.outputs.tag }}" > VERSION | |
# # 更新 GitHub Secrets 或其他存儲機制以記錄新版本 | |
# else | |
# echo "NEW_RELEASE_FOUND=false" >> $GITHUB_ENV | |
- name: Get the latest code-server release time | |
id: latest_release_time | |
run: | | |
release_time=$(curl -s https://api.github.com/repos/coder/code-server/releases/latest | jq -r '.published_at') | |
echo "RELEASE_TIME=$release_time" >> $GITHUB_ENV | |
- name: Check if new release was published within the last 24 hours | |
id: check_release_time | |
run: | | |
release_time=$(date -u -d "${{ env.RELEASE_TIME }}" +%s) | |
current_time=$(date -u +%s) | |
diff=$((current_time - release_time)) | |
echo "Time difference in seconds: $diff" | |
echo "Current time in seconds: $current_time" | |
# Check if the release is recent (within 24 hours) | |
if [ $diff -le 86400 ]; then | |
echo "NEW_RELEASE_RECENT=true" >> $GITHUB_ENV | |
else | |
echo "NEW_RELEASE_RECENT=false" >> $GITHUB_ENV | |
fi | |
- name: Build and push Docker image | |
if: env.NEW_RELEASE_RECENT == 'true' | |
run: | | |
docker build . --file Dockerfile --tag adsfaaron/vscode-server-gpu:${{ steps.latest_release.outputs.tag }} --build-arg CODE_SERVER_VERSION=${{ steps.latest_release.outputs.tag }} | |
docker push adsfaaron/vscode-server-gpu:${{ steps.latest_release.outputs.tag }} | |
# Tag and push as latest | |
docker tag adsfaaron/vscode-server-gpu:${{ steps.latest_release.outputs.tag }} adsfaaron/vscode-server-gpu:latest | |
docker push adsfaaron/vscode-server-gpu:latest | |
# Build Docker image with Dockerfile.cuda12 | |
docker build . --file Dockerfile.cuda12 --tag adsfaaron/vscode-server-gpu-cuda12:${{ steps.latest_release.outputs.tag }} --build-arg CODE_SERVER_VERSION=${{ steps.latest_release.outputs.tag }} | |
# Push the CUDA 12 image to Docker Hub | |
docker push adsfaaron/vscode-server-gpu-cuda12:${{ steps.latest_release.outputs.tag }} |