ci: login to github registry before pulling cache #82
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 | |
pull_request: | |
branches: | |
- main | |
env: | |
IMAGE_NAME: rapiddb | |
IMAGE_CACHE: docker.pkg.github.com/kruserr/rapiddb/rapiddb:cache | |
jobs: | |
rustfmt: | |
name: Formatting | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Formatting | |
run: cargo fmt --all -- --check | |
clippy: | |
name: Lint | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Lint | |
run: cargo clippy --all-targets --all-features -- -Dwarnings | |
test: | |
name: Test | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Test | |
run: cargo test | |
publish-docker: | |
name: Publish on GitHub Packages and Docker Hub | |
runs-on: ubuntu-22.04 | |
if: github.event_name == 'push' | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Login to GitHub Packages | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin | |
- name: Build image | |
run: | | |
docker build \ | |
-f tooling/Dockerfile \ | |
--cache-from $IMAGE_CACHE \ | |
--build-arg BUILDKIT_INLINE_CACHE=1 \ | |
--tag $IMAGE_NAME . | |
- name: Push image to GitHub Packages | |
run: | | |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
VERSION=cache | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
- name: Login to Docker Hub | |
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin | |
- name: Push image to Docker Hub | |
run: | | |
IMAGE_ID=docker.io/${{ github.repository }} | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
VERSION=cache | |
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |