Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ab2730f
style: remove whitespace
mujz Apr 25, 2022
fa20d34
style(docker/site.conf.t): remove whitespace
mujz Apr 26, 2022
74a43af
feat: change upstream to localhost
mujz Apr 26, 2022
e21bf05
feat(dockerfile): set bundler version and install python for node
mujz Apr 26, 2022
0455bc5
style(discourse_install): remove whitespace
mujz Apr 26, 2022
4de07fb
feat(discourse_install): handle bundler warnings
mujz Apr 26, 2022
3904c66
ci: add github workflow for pushing docker images to ECR
mujz Apr 26, 2022
508c3cc
feat(docker/dockerfile): update discourse dockerfile to latest
mujz Apr 27, 2022
34b9773
fix(.github/workflows/build-docker-images-and-push-to-ecr): update cmds
mujz Apr 27, 2022
b540a1f
ci: add ssh sooner
mujz Apr 28, 2022
62de9c5
fix(dockerfile): add public/javascripts dir
mujz Apr 28, 2022
65b74ba
fix(.github/workflows/build-docker-images-and-push-to-ecr.yml): synx err
mujz Apr 28, 2022
fec4182
ci: remove ssh upterm
mujz Apr 28, 2022
73ca4a2
ci: point to the right dockerfile
mujz Apr 28, 2022
3a8e1f0
ci: add image revision version
mujz Apr 28, 2022
d4c588e
ci: pull the latest image and push the one with the revision
mujz Apr 28, 2022
666c026
ci: use aws s3 cp not sync because sync is for directories
mujz Apr 28, 2022
85599cb
ci: set env vars across job
mujz Apr 28, 2022
5cf3e40
ci: use AWS github actions to push image to ecr, ecs task def, and svc
mujz Apr 28, 2022
5516268
ci: fix steps order
mujz Apr 28, 2022
5ede98d
ci: add env based values
mujz Apr 28, 2022
9e66f83
ci: configure credentials before deploying
mujz Apr 28, 2022
8ddacf3
ci: fix build-api by making it require setup-env
mujz Apr 28, 2022
54c6b18
ci: use needs instead of steps for inter-job outputs
mujz Apr 28, 2022
0e5a1ee
ci: fix env vars for testing
mujz Apr 28, 2022
3cb4463
ci: remove log
mujz Apr 28, 2022
cb19039
ci: typo commnuity -> community
mujz Apr 28, 2022
bf0d9d7
ci: move s3 env vars
mujz Apr 28, 2022
50820f1
ci: add some logging
mujz Apr 28, 2022
f1e282b
ci: add more logs
mujz Apr 28, 2022
1a695f9
ci: will this work?
mujz Apr 28, 2022
e66233c
ci: fix var passing around jobs
mujz Apr 28, 2022
ba82d1e
ci: let's try this now
mujz Apr 28, 2022
33de9ba
ci: how about now
mujz Apr 28, 2022
dc7a0df
ci: work please
mujz Apr 28, 2022
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
164 changes: 164 additions & 0 deletions .github/workflows/build-docker-images-and-push-to-ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: Build Docker Images and Push to AWS ECR

on:
push:
branches: [testing, master]
# TODO remove pull request after done testing
pull_request:
branches: [testing]

jobs:
setup-env:
runs-on: ubuntu-latest
outputs:
aws-s3-bloom-config-bucket: ${{ steps.branch_based.outputs.aws-s3-bloom-config-bucket }}
aws-ecs-task-def: ${{ steps.branch_based.outputs.aws-ecs-task-def }}
aws-ecs-service: ${{ steps.branch_based.outputs.aws-ecs-service }}
steps:
- name: Set Variables Depending on Current Branch
id: branch_based
run: |
echo "Running on branch ${{ github.ref }}"
if [ "${{ github.ref }}" = "refs/heads/master" ]; then
echo "::set-output name=aws-s3-bloom-config-bucket::bloom-config-production"
echo "::set-output name=aws-ecs-task-def::community-production"
echo "::set-output name=aws-ecs-service::community-production"
# TODO uncomment and delete next line elif [ "${{ github.ref }}" = "refs/heads/testing" ]; then
else
echo "::set-output name=aws-s3-bloom-config-bucket::bloom-config-testing"
echo "::set-output name=aws-ecs-task-def::community-testing"
echo "::set-output name=aws-ecs-service::community-testing"
fi

build-proxy:
runs-on: ubuntu-latest
outputs:
docker-image: ${{ steps.docker-image.outputs.image }}
steps:
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_COMMUNITY_CI_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_COMMUNITY_CI_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_REGION }}

# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1

# - uses: actions/checkout@v3

- name: Set docker image name and tag
id: docker-image
env:
AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: discourse-proxy
IMAGE_TAG: ${{ github.sha }}
run: |
echo "::set-output name=image::$AWS_ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
echo "::set-output name=untagged-image::$AWS_ECR_REGISTRY/$ECR_REPOSITORY"

# - name: Build, tag, and push image to Amazon ECR
# id: build-image
# run: |
# docker pull ${{ steps.docker-image.outputs.untagged-image }}
# docker build -t ${{ steps.docker-image.outputs.image }} --cache-from ${{ steps.docker-image.outputs.untagged-image }} -f ./docker/nginx.dockerfile ./docker
# docker push ${{ steps.docker-image.outputs.image }}

build-api:
runs-on: ubuntu-latest
needs: setup-env
outputs:
docker-image: ${{ steps.build-image.outputs.image }}
steps:
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_COMMUNITY_CI_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_COMMUNITY_CI_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_REGION }}

# - name: Login to Amazon ECR
# id: login-ecr
# uses: aws-actions/amazon-ecr-login@v1

# - uses: actions/checkout@v3

# - name: Pull .env from S3
# run: aws s3 cp "s3://${{ needs.setup-env.outputs.aws-s3-bloom-config-bucket }}/community/api.env" ./.env

# - name: Set environment variables
# run: cat .env >> $GITHUB_ENV

# - name: Build, tag, and push image to Amazon ECR
# id: build-image
# env:
# AWS_ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
# ECR_REPOSITORY: discourse-api
# IMAGE_TAG: ${{ github.sha }}
# run: |
# docker pull $AWS_ECR_REGISTRY/$ECR_REPOSITORY
# docker build -t $AWS_ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --cache-from $AWS_ECR_REGISTRY/$ECR_REPOSITORY -f ./docker/dockerfile --build-arg DISCOURSE_MAXMIND_LICENSE_KEY=${DISCOURSE_MAXMIND_LICENSE_KEY} .
# docker push $AWS_ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
- name: Output
id: build-image
env:
AWS_ECR_REGISTRY: 673099801448.dkr.ecr.eu-west-1.amazonaws.com
ECR_REPOSITORY: discourse-api
IMAGE_TAG: ${{ github.sha }}
run: |
echo "::set-output name=image::$AWS_ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
echo "$AWS_ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

# - name: Compile assets and upload them to S3
# env:
# API_DOCKER_IMAGE: ${{ steps.build-image.outputs.image }}
# run: |
# echo "${{ steps.build-image.outputs.image }}"
# docker network create discourse
# docker run --rm -d --name discourse_db -e POSTGRES_DB=discourse -e POSTGRES_USER=discourse -e POSTGRES_PASSWORD=password --network discourse postgres:13.4-alpine
# docker run --rm -d --name discourse_cache --network discourse redis:alpine
# docker run --rm -i --name assets_compiler --env-file .env -e DISCOURSE_DB_HOST=discourse_db -e DISCOURSE_DB_PASSWORD=password -e DISCOURSE_REDIS_HOST=discourse_cache --network discourse $API_DOCKER_IMAGE sh -c 'bundle exec rake db:prepare && bundle exec rake assets:precompile && bundle exec rake s3:upload_assets'

deploy:
runs-on: ubuntu-latest
needs: [setup-env, build-proxy, build-api]
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_COMMUNITY_CI_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_COMMUNITY_CI_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Download task definition
run: |
echo "${{ needs.setup-env.outputs.aws-ecs-task-def }}"
echo "${{ needs.build-proxy.outputs.docker-image }}"
echo "${{ needs.build-api.outputs.docker-image }}"
echo "${{ needs.setup-env.outputs.aws-ecs-service }}"
aws ecs describe-task-definition --task-definition ${{ needs.setup-env.outputs.aws-ecs-task-def }} --query taskDefinition > task-definition.json

- name: Update Task Definition Proxy Image
id: proxy-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: proxy
image: ${{ needs.build-proxy.outputs.docker-image }}

- name: Update Task Definition API Image
id: api-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.proxy-task-def.outputs.task-definition }}
container-name: api
image: ${{ needs.build-api.outputs.docker-image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.api-task-def.outputs.task-definition }}
service: ${{ needs.setup-env.outputs.aws-ecs-service }}
cluster: bloom
wait-for-service-stability: true
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ services:
DISCOURSE_SECRET_KEY_BASE: "${DISCOURSE_SECRET_KEY_BASE}"
#entrypoint: ["/bin/sh", "sleep", "10000"]
command: ["no-compile"]
web:

web:
build:
context: ./docker
dockerfile: ./nginx.dockerfile
Expand All @@ -58,32 +58,32 @@ services:
- ./uploads:/var/www/discourse/public/uploads
ports:
- 80:80
environment:
environment:
DISCOURSE_HOST: "${DISCOURSE_HOST}"
depends_on:
- app
command: ["/bin/sh" , "/etc/nginx/nginx.sh"]

cache:
image: redis
ports:
- 6379:6379

mail:
image: namshi/smtp
restart: always
volumes:
- ./log:/var/log/exim4
environment:
environment:
SES_USER: "${DISCOURSE_SMTP_USER_NAME}"
SES_PASSWORD: "${DISCOURSE_SMTP_PASSWORD}"
SES_REGION: "${AWS_REGION}"

logrotate:
logrotate:
image: blacklabelops/logrotate
volumes:
- ./log:/var/lib/discourse
environment:
environment:
LOGS_DIRECTORIES: "/var/lib/discourse"
LOGROTATE_SIZE: "10M"
LOGROTATE_INTERVAL: "hourly"
Expand Down
1 change: 0 additions & 1 deletion docker/discourse_first_run

This file was deleted.

13 changes: 0 additions & 13 deletions docker/discourse_install.sh

This file was deleted.

33 changes: 0 additions & 33 deletions docker/discourse_run.sh

This file was deleted.

Loading