Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Include image tag in built image #1125

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ jobs:
pip install pre-commit
pre-commit run --all-files

get-image-tag:
name: Get image tag
runs-on: ubuntu-latest
outputs:
image-tag: ${{ steps.get-image-tag.outputs.image-tag }}
steps:
- name: Get image tag
id: get-image-tag
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "image-tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
else
echo "image-tag=${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi

build-images:
name: Build images
runs-on: ubuntu-latest
Expand All @@ -49,6 +64,9 @@ jobs:
image:
- api
- ingestion_server
needs:
- get-image-tag
- lint
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -67,6 +85,8 @@ jobs:
cache-from: type=gha,scope=${{ matrix.image }}
cache-to: type=gha,scope=${{ matrix.image }}
outputs: type=docker,dest=/tmp/${{ matrix.image }}.tar
build-args: |
SEMANTIC_VERSION=${{ needs.get-image-tag.outputs.image-tag }}
krysal marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload image `${{ matrix.image }}`
uses: actions/upload-artifact@v3
Expand All @@ -80,6 +100,7 @@ jobs:
runs-on: ubuntu-latest
needs:
- build-images
- get-image-tag

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -120,6 +141,8 @@ jobs:
cache-from: type=gha,scope=nginx
cache-to: type=gha,scope=nginx
outputs: type=docker,dest=/tmp/api-nginx.tar
build-args: |
SEMANTIC_VERSION=${{ needs.get-image-tag.outputs.image-tag }}

- name: Upload image `api-nginx`
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -351,6 +374,7 @@ jobs:
needs:
- test-ing
- test-api
- get-image-tag
- build-nginx
permissions:
packages: write
Expand Down Expand Up @@ -381,29 +405,23 @@ jobs:
docker tag openverse-${{ matrix.image }} \
ghcr.io/wordpress/openverse-${{ matrix.image }}:latest
docker tag openverse-${{ matrix.image }} \
ghcr.io/wordpress/openverse-${{ matrix.image }}:${{ github.sha }}
docker push --all-tags ghcr.io/wordpress/openverse-${{ matrix.image }}

- name: Tag image `${{ matrix.image }}` (release)
if: github.event_name == 'release'
run: |
docker tag openverse-${{ matrix.image }} \
ghcr.io/wordpress/openverse-${{ matrix.image }}:${{ github.ref_name }}
ghcr.io/wordpress/openverse-${{ matrix.image }}:${{ needs.get-image-tag.outputs.image-tag }}
docker push --all-tags ghcr.io/wordpress/openverse-${{ matrix.image }}

deploy-staging:
name: Deploy staging API
runs-on: ubuntu-latest
# Deploy a new version when `main` is pushed to in this repository
if: github.event_name == 'push' && github.repository == 'WordPress/openverse-api'
needs: push

needs:
- push
- get-image-tag
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/staging-deploy
with:
tag: ${{ github.sha }}
tag: ${{ needs.get-image-tag.outputs.image-tag }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
Expand Down
7 changes: 7 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ COPY /static /app/static
# Only environment variables with this prefix will be available in the template
ENV NGINX_ENVSUBST_FILTER="DJANGO_NGINX_"
ENV DJANGO_NGINX_ENVIRONMENT="local"
# Add the release version to the docker container
ARG SEMANTIC_VERSION
ENV DJANGO_NGINX_GIT_REVISION=$SEMANTIC_VERSION

#######
# API #
Expand Down Expand Up @@ -90,6 +93,10 @@ USER opener
# Copy code into the final image
COPY --chown=opener . /api/

# Add the release version to the docker container
ARG SEMANTIC_VERSION
ENV SEMANTIC_VERSION=$SEMANTIC_VERSION

# Exposes
# - 8000: Dev server for API Django app
# - 3000: Sphinx live server
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ services:
- es-data:/usr/share/elasticsearch/data

web:
build: ./api/
build:
context: ./api/
args:
SEMANTIC_VERSION: ${SEMANTIC_VERSION:-v1.0.0}
image: openverse-api
volumes:
- ./api:/api
Expand Down