Merge pull request #692 from sapuri/docker/pkg-config-2 #550
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: app | |
on: push | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
cache: pipenv | |
- name: Install pipenv | |
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python | |
- name: Install dependencies | |
run: pipenv sync --dev | |
- name: Lint | |
run: pipenv run lint | |
test: | |
runs-on: ubuntu-latest | |
services: | |
mysql: | |
image: mysql:8.0 | |
ports: | |
- 3306:3306 | |
env: | |
MYSQL_ROOT_PASSWORD: password | |
MYSQL_DATABASE: ci | |
options: >- | |
--health-cmd "mysqladmin ping" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
ALLOWED_HOSTS: 127.0.0.1 | |
DATABASE_ENGINE: django.db.backends.mysql | |
DATABASE_NAME: ci | |
DATABASE_USER: root | |
DATABASE_PASSWORD: password | |
DATABASE_HOST: 127.0.0.1 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
cache: pipenv | |
- name: Install pipenv | |
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python | |
- name: Install dependencies | |
run: pipenv sync | |
- name: Migration | |
run: pipenv run python manage.py migrate | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
workload_identity_provider: projects/682889726379/locations/global/workloadIdentityPools/github-actions/providers/github-actions | |
service_account: github@srandom.iam.gserviceaccount.com | |
- name: Test | |
run: pipenv run test | |
deploy: | |
if: github.ref == 'refs/heads/master' | |
needs: [lint, test] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
CLOUDSDK_CORE_DISABLE_PROMPTS: 1 | |
SERVICE: app | |
REGION: asia-northeast1 | |
IMAGE_APP: asia-northeast1-docker.pkg.dev/srandom/app/app:${{ github.sha }} | |
IMAGE_CMD_UPDATE_MUSIC: asia-northeast1-docker.pkg.dev/srandom/cmd/update-music:${{ github.sha }} | |
IMAGE_CMD_EXPORT2CSV: asia-northeast1-docker.pkg.dev/srandom/cmd/export2csv:${{ github.sha }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
workload_identity_provider: projects/682889726379/locations/global/workloadIdentityPools/github-actions/providers/github-actions | |
service_account: github@srandom.iam.gserviceaccount.com | |
- name: Configure auth | |
run: gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev | |
- name: Build and push containers | |
run: | | |
git clone https://github.com/planetscale/django_psdb_engine.git | |
./scripts/decrypt-env.sh production | |
docker build . -f docker/Dockerfile -t ${{ env.IMAGE_APP }} | |
docker build . -f docker/Dockerfile_update_music -t ${{ env.IMAGE_CMD_UPDATE_MUSIC }} | |
docker build . -f docker/Dockerfile_export2csv -t ${{ env.IMAGE_CMD_EXPORT2CSV }} | |
docker push ${{ env.IMAGE_APP }} | |
docker push ${{ env.IMAGE_CMD_UPDATE_MUSIC }} | |
docker push ${{ env.IMAGE_CMD_EXPORT2CSV }} | |
- name: Deploy to Cloud Run | |
uses: google-github-actions/deploy-cloudrun@v1 | |
with: | |
service: ${{ env.SERVICE }} | |
image: ${{ env.IMAGE_APP }} | |
region: ${{ env.REGION }} | |
- name: Update Cloud Run Jobs | |
run: | | |
gcloud beta run jobs update update-music --image ${{ env.IMAGE_CMD_UPDATE_MUSIC }} --region asia-northeast1 | |
gcloud beta run jobs update export2csv --image ${{ env.IMAGE_CMD_EXPORT2CSV }} --region asia-northeast1 |