generated from freeCodeCamp/template
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workflow to build images (#299)
Co-authored-by: Mrugesh Mohapatra <[email protected]>
- Loading branch information
1 parent
eecabb0
commit afda8b6
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Build | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-22.04 | ||
environment: staging # Hardcoded for now. TODO: use a matrix? | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [20.x] | ||
site_tlds: ['dev'] | ||
apps: ['backend', 'frontend', 'cron'] | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Create a tagname | ||
id: tagname | ||
run: | | ||
echo "tagname=$(git rev-parse --short HEAD)-$(date +%Y%m%d)-$(date +%H%M)" >> $GITHUB_ENV | ||
- name: Build & Tag Images | ||
# We pass NEXT_PUBLIC_STRAPI_BACKEND_URL as a build arg to all apps, | ||
# even though only the frontend needs it. The other builds will ignore | ||
# it. | ||
run: | | ||
docker build . \ | ||
--tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:$tagname \ | ||
--tag registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:latest \ | ||
--build-arg NEXT_PUBLIC_STRAPI_BACKEND_URL=${{ secrets.NEXT_PUBLIC_STRAPI_BACKEND_URL }} \ | ||
--file docker/${{ matrix.apps }}/Dockerfile | ||
- name: Install doctl | ||
uses: digitalocean/action-doctl@v2 | ||
with: | ||
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | ||
|
||
- name: Log in to DigitalOcean Container Registry with short-lived credentials | ||
run: doctl registry login --expiry-seconds 1200 | ||
|
||
- name: Push image to DigitalOcean Container Registry | ||
run: | | ||
docker push registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:$tagname | ||
docker push registry.digitalocean.com/${{ secrets.DOCR_NAME }}/${{ matrix.site_tlds }}/publish-${{ matrix.apps }}:latest |