Update cd-workflow.yml #36
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: Docker-CI | |
on: | |
push: | |
branches: | |
- dev-update-base | |
pull_request: | |
branches: | |
- dev-update-base | |
types: [opened, synchronize, reopened] | |
jobs: | |
build-push: | |
# requires dependency from step above | |
name: Build and push Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v2 | |
- name: Set up archived Oracle JDK 17.0.3.1 | |
uses: oracle-actions/setup-java@v1 | |
with: | |
website: oracle.com | |
release: 17 | |
version: 17.0.3.1 | |
- name: Maven build | |
run: | | |
echo "maven build - Clean install" | |
mvn clean install -Dmaven.test.skip=true | |
mkdir -p target/dependency && (cd target/dependency; jar -xf ../elrrdatasync-0.0.1-SNAPSHOT.jar) | |
- name: Docker login | |
env: | |
DOCKER_USER: ${{ secrets.DOCKER_USER }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: | | |
echo "Authenticate to Docker" | |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD | |
- name: Docker build | |
run: | | |
echo "Start docker build" | |
#docker build . -t openlxp/elrr-datasync | |
docker build --build-arg JAR_FILE="./target/elrrdatasync-0.0.1-SNAPSHOT.jar" --file Dockerfile -t openlxp/elrr-datasync . | |
- name: Push Image to Dockerhub | |
run: | | |
echo "Push new image to the Dockerhub repository" | |
docker push openlxp/elrr-datasync | |
# Push image to Amazon ECR | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: ECR Login | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
mask-password: 'true' | |
- name: Build, tag, and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPO }} | |
IMAGE_TAG: elrrdatasync | |
run: | | |
echo "Starting docker build" | |
docker build --build-arg JAR_FILE="./target/elrrdatasync-0.0.1-SNAPSHOT.jar" --file Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
echo "Pushing image to ECR..." | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |