setup worflow to push docker image to ghcr #11
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: Build and Push Docker Image | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache Maven packages | |
uses: actions/cache@v2 | |
with: | |
path: ~/.m2 | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: ${{ runner.os }}-m2 | |
- name: Set up Maven settings.xml | |
run: | | |
mkdir -p ~/.m2 | |
echo "<settings> | |
<servers> | |
<server> | |
<id>github-webank</id> | |
<username>${{ github.actor }}</username> | |
<password>${{ secrets.WEBANK_ACCESS_TOKEN }}</password> | |
</server> | |
</servers> | |
</settings>" > ~/.m2/settings.xml | |
- name: Build JAR | |
run: mvn -f online-banking-app/pom.xml clean package -DskipTests | |
- name: Verify JAR File Exists | |
run: ls -l ./online-banking-app/target/online-banking-app-0.1-SNAPSHOT.jar | |
- name: Log in to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GHCR_PAT }} | |
- name: Build Docker image | |
run: | | |
docker build -t ghcr.io/adorsys-gis/webank-online-banking:latest . | |
- name: Push Docker image to GHCR | |
run: | | |
docker push ghcr.io/adorsys-gis/webank-online-banking:latest |