add cache and fix tag date #8
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: Create a Docker image and deploy to Kubernetes | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Get commit date | |
id: get_commit_date | |
run: | | |
COMMIT_DATE=$(git log -1 --format=%cd --date=format:'%Y%m%d') | |
echo "COMMIT_DATE=$COMMIT_DATE" >> $GITHUB_ENV | |
- name: Build Docker image | |
env: | |
VITE_CESIUM_TOKEN: ${{ secrets.VITE_CESIUM_TOKEN }} | |
VITE_N2YO_API_KEY: ${{ secrets.VITE_N2YO_API_KEY }} | |
COMMIT_DATE: ${{ steps.get_commit_date.outputs.COMMIT_DATE }} | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: soylumu/orbital-satellite-tracker:${{ env.COMMIT_DATE }}, soylumu/orbital-satellite-tracker:latest | |
platforms: linux/amd64,linux/arm64,linux/arm/v7 | |
build-args: | | |
VITE_CESIUM_TOKEN=${VITE_CESIUM_TOKEN} | |
VITE_N2YO_API_KEY=${VITE_N2YO_API_KEY} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
- name: Set up kubectl | |
run: | | |
mkdir -p ~/.kube | |
echo "${{ secrets.KUBE_CONFIG }}" > ~/.kube/config | |
- name: Deploy to Kubernetes | |
run: | | |
kubectl apply -f manifests/deployment.yaml | |
kubectl apply -f manifests/service.yaml | |
kubectl apply -f manifests/ingress.yaml |