forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a GitHub Action for building and publishing Docker image (line#630)
* Add a GitHub Action for building and publishing Docker image Motivation: As a part of automation, it would be nice to automatically push Docker image when a new version is released. Modifications: - Add docker.yml for a new GitHub Action job Result: Use GitHub Actions to push Docker image
- Loading branch information
Showing
2 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Publish Docker image | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
push_to_registry: | ||
name: Push Docker image to Docker Hub | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: 11 | ||
|
||
- name: Restore Gradle cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.gradle/wrapper/dists | ||
~/.gradle/caches/jars-3 | ||
~/.gradle/caches/modules-2 | ||
~/.gradle/caches/package-lists | ||
~/.gradle/caches/sphinx-binary | ||
~/.gradle/go/binary | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Build Docker image | ||
run: ./gradlew :dist:docker | ||
shell: bash | ||
|
||
- name: Extract release version | ||
id: release-version | ||
uses: actions/github-script@v4 | ||
with: | ||
# Extract a release version from 'refs/tags/centraldogma-x.y.z' tag. | ||
script: | | ||
const version = context.ref.replace(/.*centraldogma-/, '') | ||
console.log('Release version: ' + version) | ||
return version | ||
result-encoding: string | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Push Docker image | ||
run: | | ||
docker push line/centraldogma:${{ steps.release-version.outputs.result }} | ||
docker push line/centraldogma:latest | ||
shell: bash | ||
|
||
- name: Clean up Gradle cache | ||
run: | | ||
rm -f ~/.gradle/caches/modules-2/modules-2.lock | ||
rm -f ~/.gradle/caches/modules-2/gc.properties | ||
shell: bash |
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