ci #2
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: ci | |
on: | |
push: | |
branches: ["main"] | |
paths: | |
- "Dockerfile" | |
workflow_dispatch: | |
concurrency: | |
# Support push/pr as event types with different behaviors each: | |
# 1. push: queue up builds | |
# 2. pr: only allow one run per PR | |
group: ${{ github.workflow }}-${{ github.event_name }}${{ github.event.pull_request.number }} | |
# If there is already a workflow running for the same pull request, cancel it | |
cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
env: | |
AWS_REGION: "eu-central-1" | |
jobs: | |
build: | |
name: "Build image: ${{ matrix.images.name }}" | |
runs-on: | |
group: ubuntu-runners | |
strategy: | |
fail-fast: false | |
matrix: | |
images: | |
- name: github-actions-runner | |
dockerfile: ./Dockerfile | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- 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: eu-central-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: | | |
${{ steps.login-ecr.outputs.registry }}/${{ matrix.images.name }} | |
flavor: | | |
latest=auto | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=sha | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build, tag and cache the image | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: ${{ matrix.images.dockerfile }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
outputs: type=docker,dest=/tmp/image-${{ matrix.images.name }}.tar | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: image-${{ matrix.images.name }} | |
path: /tmp/image-${{ matrix.images.name }}.tar | |
publish: | |
needs: [build] | |
name: "Publish image: ${{ matrix.images.name }}" | |
runs-on: | |
group: ubuntu-runners | |
strategy: | |
fail-fast: false | |
matrix: | |
images: | |
- name: github-actions-runner | |
steps: | |
- 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: eu-central-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Download artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: image-${{ matrix.images.name }} | |
path: /tmp | |
- name: Push the image to ECR | |
run: | | |
docker load --input /tmp/image-${{ matrix.images.name }}.tar | |
docker image push --all-tags ${{ steps.login-ecr.outputs.registry }}/${{ matrix.images.name }} |