build #12
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: build | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/[email protected] | |
- name: Install Kubernetes tools | |
uses: yokawasa/[email protected] | |
with: | |
setup-tools: | | |
yq | |
yq: "4.16.2" | |
- name: Docker Build | |
run: docker build . -t justshare | |
- if: ${{ !(github.event_name == 'push' && github.ref == 'refs/heads/main') }} | |
run: exit 0 | |
- | |
name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push backend image | |
if: github.ref == 'refs/heads/main' | |
run: | | |
SERVER_IMAGE_ID=ghcr.io/justshare-io/justshare | |
# Change all uppercase to lowercase | |
SERVER_IMAGE_ID=$(echo $SERVER_IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo SERVER_IMAGE_ID=$SERVER_IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag justshare $SERVER_IMAGE_ID:$VERSION | |
docker push $SERVER_IMAGE_ID:$VERSION | |
yq -i e ".services.justshare.image |= \"$(docker inspect --format='{{index .RepoDigests 0}}' $SERVER_IMAGE_ID:$VERSION)\"" docker-compose.prod.yaml | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@main | |
with: | |
version: 'latest' | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
export_default_credentials: true | |
- name: Configure Docker | |
run: | | |
gcloud auth configure-docker | |
- name: Get Kubernetes credentials | |
run: | | |
gcloud container clusters get-credentials ${{ secrets.GKE_CLUSTER }} --zone ${{ secrets.GKE_ZONE }} --project ${{ secrets.GCP_PROJECT_ID }} | |
- name: Deploy to Kubernetes | |
run: echo "TODO breadchris deploy to k8s via go command" |