Skip to content

Commit

Permalink
Build and publish Docker image in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Mirić committed Feb 27, 2023
1 parent 70d993f commit 8416806
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ name: Release

on:
push:
branches:
- master
tags:
- 'v*.*.*'

jobs:
release:
name: Release
name: Release GitHub
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
strategy:
matrix:
os: [ ubuntu-latest ]
Expand Down Expand Up @@ -56,3 +59,54 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

docker:
name: Build and publish Docker image
runs-on: ubuntu-latest
env:
IMAGE_REPOSITORY: ${{ github.repository }}
VERSION: ${{ github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build image
run: docker build -t "$IMAGE_REPOSITORY" .
- name: Build k6 binary
run: |
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD:/xk6" \
"$IMAGE_REPOSITORY" build master \
--with github.com/mostafa/xk6-kafka \
--with github.com/grafana/xk6-output-influxdb
- name: Check k6 binary
run: |
./k6 version
./k6 version | grep -qz 'xk6-output-influxdb.*xk6-kafka'
- name: Log into ghcr.io
if: ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v') }}
run: |
# Log into GitHub Container Registry
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Publish master image to ghcr.io
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "Publish as ghcr.io/$IMAGE_REPOSITORY:$VERSION"
docker tag "$IMAGE_REPOSITORY" "ghcr.io/$IMAGE_REPOSITORY:master"
docker push "ghcr.io/$IMAGE_REPOSITORY:master"
- name: Publish tagged version image to ghcr.io
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
VERSION="${VERSION#v}"
echo "Publish as ghcr.io/${IMAGE_REPOSITORY}:${VERSION}"
docker tag "$IMAGE_REPOSITORY" "ghcr.io/${IMAGE_REPOSITORY}:${VERSION}"
docker push "ghcr.io/${IMAGE_REPOSITORY}:${VERSION}"
# We also want to tag the latest stable version as latest
if [[ ! "$VERSION" =~ (RC|rc) ]]; then
echo "Publish as ghcr.io/${IMAGE_REPOSITORY}:latest"
docker tag "$IMAGE_REPOSITORY" "ghcr.io/${IMAGE_REPOSITORY}:latest"
docker push "ghcr.io/${IMAGE_REPOSITORY}:latest"
fi

0 comments on commit 8416806

Please sign in to comment.