This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
75 lines (60 loc) · 2.33 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Build Docker Image & Pack Source Code
on:
push:
tags:
- 'v*'
# git tag -a v1.0.0
# git push origin v1.0.0
env:
IMAGE_NAME: baiduwp-php
jobs:
build_and_upload:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Parse version from tag name
run: echo "VERSION=$(echo $GITHUB_REF | sed -n 's/refs\/tags\/v\(.*\)/\1/p')" >> $GITHUB_ENV
- name: Build Docker image
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}
- name: Log into Docker Hub
run: echo "${{ secrets.DOCKER_ACCESS_TOKEN }}" | docker login -u yuantuo666 --password-stdin
- name: Push Docker image
run: |
IMAGE_ID=yuantuo666/$IMAGE_NAME
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=${{ env.VERSION }}
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
[ "$VERSION" != "latest" ] && docker tag $IMAGE_NAME $IMAGE_ID:latest
[ "$VERSION" != "latest" ] && docker push $IMAGE_ID:latest
- name: Run Docker image
run: docker run -itd --name baiduwp-php ${{ env.IMAGE_NAME }}
- name: Install zip
run: docker exec baiduwp-php apt-get update && docker exec baiduwp-php apt-get install -y zip
- name: Pack source code
run: docker exec baiduwp-php zip -r /tmp/baiduwp-php.zip /app
- name: Copy source code
run: docker cp baiduwp-php:/tmp/baiduwp-php.zip ./baiduwp-php-v${{ env.VERSION }}.zip
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
draft: true
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./baiduwp-php-v${{ env.VERSION }}.zip
asset_name: baiduwp-php-v${{ env.VERSION }}.zip
asset_content_type: application/x-zip-compressed