-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
106 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
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
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
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,98 @@ | ||
name: Publish | ||
on: | ||
workflow_call: | ||
inputs: | ||
commithash: | ||
description: "Commit hash (version) of the image to package and publish" | ||
type: string | ||
required: true | ||
env: | ||
DOCKER_BUILDKIT: 1 | ||
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | ||
|
||
jobs: | ||
publish: | ||
name: Publish Koski Docker image | ||
runs-on: ubuntu-20.04 | ||
permissions: | ||
id-token: write | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.commithash }} | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
role-to-assume: ${{ secrets.ECR_ROLE }} | ||
role-duration-seconds: 3600 | ||
role-session-name: KoskiPublishEcr-${{ inputs.commithash }} | ||
aws-region: eu-west-1 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
with: | ||
registries: ${{ secrets.ECR_ACCOUNT_ID }} | ||
mask-password: "true" | ||
|
||
- name: Check if container image already exists in ECR | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: koski | ||
IMAGE_TAG: ${{ inputs.commithash }} | ||
id: check-image | ||
run: | | ||
echo "image-exists=$(docker manifest inspect $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG > /dev/null 2>&1 ; echo $?)" >> $GITHUB_OUTPUT | ||
- name: Cache Maven packages | ||
uses: actions/cache@v3 | ||
if: steps.check-image.outputs.image-exists != '0' | ||
with: | ||
path: ~/.m2/repository | ||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: | | ||
${{ runner.os }}-maven- | ||
- name: Set up Java 11 | ||
uses: actions/setup-java@v4 | ||
if: steps.check-image.outputs.image-exists != '0' | ||
with: | ||
java-version: "11" | ||
architecture: "x64" | ||
distribution: "zulu" | ||
cache: "maven" | ||
|
||
- name: Setup settings.xml | ||
uses: s4u/maven-settings-action@v2.8.0 | ||
if: steps.check-image.outputs.image-exists != '0' | ||
with: | ||
servers: '[{"id": "github","configuration": {"httpHeaders": {"property": {"name": "Authorization","value": "Bearer ${{ secrets.GITHUB_TOKEN }}"}}}}]' | ||
|
||
- name: Restore target dir | ||
uses: actions/cache/restore@v4 | ||
if: steps.check-image.outputs.image-exists != '0' | ||
with: | ||
path: "target/" | ||
key: ${{ runner.os }}-target-${{ inputs.commithash }} | ||
fail-on-cache-miss: "true" | ||
|
||
- name: Build application and publish it to Github Packages | ||
if: steps.check-image.outputs.image-exists != '0' | ||
run: | | ||
make dist version=${{ inputs.commithash }} | ||
mvn war:war deploy:deploy --batch-mode -Dmaven.skip.install=true -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/Opetushallitus/koski | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
if: steps.check-image.outputs.image-exists != '0' | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: koski | ||
IMAGE_TAG: ${{ inputs.commithash }} | ||
run: | | ||
docker build -f docker-build/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg KOSKI_VERSION=$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
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