Skip to content

Commit

Permalink
chore: update docker config and github action
Browse files Browse the repository at this point in the history
  • Loading branch information
cooderl committed Feb 28, 2024
1 parent 6b9e088 commit ced4f99
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 143 deletions.
232 changes: 96 additions & 136 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,164 +9,124 @@ on:
- "v*.*.*"

concurrency:
group: docker-release-${{ github.ref }}
group: docker-release
cancel-in-progress: true

jobs:
build-web-images:
runs-on: ubuntu-20.04
check-env:
permissions:
contents: none
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
check-docker: ${{ steps.check-docker.outputs.defined }}
steps:
- id: check-docker
env:
DOCKER_HUB_NAME: ${{ secrets.DOCKER_HUB_NAME }}
if: ${{ env.DOCKER_HUB_NAME != '' }}
run: echo "defined=true" >> $GITHUB_OUTPUT

release-images:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
packages: write
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
sudo apt update && sudo apt install -y nodejs npm
- name: Set up QEMU (optional)
uses: docker/setup-qemu-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-web:latest" >> $GITHUB_ENV
else
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build and publish image for main branch or tag push event
env:
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
run: |
docker buildx build \
--build-arg name=app \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/wewe-rss-web" \
--label "org.opencontainers.image.description=wewe-rss web image" \
--push \
--target web \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \
-t ${DOCKER_REPO_TAGGED} \
-f Dockerfile \
.
uses: docker/setup-buildx-action@v3

push-web-images-to-docker-hub:
needs: build-web-images
runs-on: ubuntu-20.04
if: github.repository == 'cooderl/wewe-rss'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_NAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Pull image from GitHub Container Registry
run: docker pull ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}}
- name: Tag image with Docker Hub repository name and version tag
run: docker tag ghcr.io/${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}} ${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}}
- name: Push image to Docker Hub
run: docker push ${{ github.repository_owner }}/wewe-rss-web:${{env.IMAGE_TAG}}

build-server-images:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Dependencies
run: |
sudo apt update && sudo apt install -y nodejs npm
- name: Set up QEMU (optional)
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-server:latest" >> $GITHUB_ENV
else
echo "DOCKER_REPO_TAGGED=ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Build and publish image for main branch or tag push event
env:
DOCKER_REPO_TAGGED: ${{ env.DOCKER_REPO_TAGGED }}
run: |
docker buildx build \
--build-arg name=app \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/wewe-rss-server" \
--label "org.opencontainers.image.description=wewe-rss server image" \
--push \
--target server \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache \
-t ${DOCKER_REPO_TAGGED} \
-f Dockerfile \
.

push-server-images-to-docker-hub:
needs: build-server-images
runs-on: ubuntu-20.04
if: github.repository == 'cooderl/wewe-rss'
- name: Extract Docker metadata (web)
id: meta-ordinary
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-web
ghcr.io/cooderl/wewe-rss-web
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ github.ref_name }},enable=true
flavor: latest=false

- name: Build and push Docker image (web)
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta-ordinary.outputs.tags }}
labels: ${{ steps.meta-ordinary.outputs.labels }}
target: web
platforms: linux/amd64,linux/arm/v7,linux/arm64
cache-from: type=gha,scope=docker-release
cache-to: type=gha,mode=max,scope=docker-release

- name: Extract Docker metadata (server)
id: meta-ordinary
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-server
ghcr.io/cooderl/wewe-rss-server
tags: |
type=raw,value=latest,enable=true
type=raw,value=${{ github.ref_name }},enable=true
flavor: latest=false

- name: Build and push Docker image (server)
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta-ordinary.outputs.tags }}
labels: ${{ steps.meta-ordinary.outputs.labels }}
target: server
platforms: linux/amd64,linux/arm/v7,linux/arm64
cache-from: type=gha,scope=docker-release
cache-to: type=gha,mode=max,scope=docker-release

description:
runs-on: ubuntu-latest
needs: check-env
if: needs.check-env.outputs.check-docker == 'true'
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
- uses: actions/checkout@v4

- name: Docker Hub Description(web)
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_NAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-web

- name: Docker Hub Description(server)
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_NAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Set DOCKER_REPO_TAGGED based on branch or tag
run: |
if [[ "${{ github.ref_name }}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Pull image from GitHub Container Registry
run: docker pull ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}}
- name: Tag image with Docker Hub repository name and version tag
run: docker tag ghcr.io/${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}} ${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}}
- name: Push image to Docker Hub
run: docker push ${{ github.repository_owner }}/wewe-rss-server:${{env.IMAGE_TAG}}
repository: ${{ secrets.DOCKER_HUB_NAME }}/wewe-rss-server
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ ENV NODE_ENV=production
ENV NEXT_PUBLIC_SERVER_ORIGIN_URL="http://localhost:4000"
ENV NEXT_PUBLIC_ENV=prod

CMD [ "npm", "run", "start" ]


CMD ["npm", "run", "start"]


FROM base AS server
Expand All @@ -50,4 +48,4 @@ ENV MAX_REQUEST_PER_MINUTE=60
ENV AUTH_CODE=""
ENV DATABASE_URL=""

CMD [ "npm", "run", "start:migrate:prod" ]
CMD ["npm", "run", "start:migrate:prod"]
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ services:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
environment:
# 请修改为自己的密码
MYSQL_ROOT_PASSWORD: 123456
TZ: 'Asia/Shanghai'
ports:
- 3306:3306

server:
image: cooderl/wewe-rss-server
image: cooderl/wewe-rss-server:latest
ports:
- 4000:4000
depends_on:
- mysql
- db
environment:
# 数据库连接地址
- DATABASE_URL="mysql://root:123456@db:3306/wewe-rss"
Expand All @@ -27,7 +28,7 @@ services:
- SERVER_ORIGIN_URL=http://localhost:4000

web:
image: cooderl/wewe-rss-web
image: cooderl/wewe-rss-web:latest
ports:
- 3000:3000
environment:
Expand Down

0 comments on commit ced4f99

Please sign in to comment.